views.py

SETTINGS_PATH = os.path.normpath(os.path.dirname(__file__))
img_dir = os.path.join(SETTINGS_PATH, "inc/img/")

def get_image(request):
    for file in os.listdir(img_dir):
        h = []
        h.append(file)
        for l in h:
            r = l.endswith('.jpg') or l.endswith('.png') or l.endswith('.gif')
            if r == True:
                dd = []
                dd.append(l)
                return render_to_response('index.html', dd)

url.py

urlpatterns = patterns('',
    url(r'^$', get_image),

settings.py

PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))

TEMPLATE_DIRS = (
    os.path.join(PROJECT_ROOT, "inc/html"),
)

How to render the items in the list dd = [] returned from the function get_image in the template?

index.html

<ul>
            {% for object in dd %}
            <li><img src="views.img_dir{{% views.img_dir.object.get_absolute_url %}}"></li>
            <li><img src="views.img_dir{{% views.img_dir.dd.get_absolute_url %}}"></li>
            <li><img src='views.img_dir{{% get_image object.get_absolute_url %}}'></li>
            {% endfor %}
            </ul>

asked 02 Sep '13, 01:53

simbha's gravatar image

simbha
112
accept rate: 0%

Be the first one to answer this question!
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×40
×8
×5

Asked: 02 Sep '13, 01:53

Seen: 756 times

Last updated: 02 Sep '13, 01:53

powered by OSQA