This is a sample view code
def link(reqest):
title = ['Home Page', 'Current Time', '10 hours later']
return render_to_response('time.html', title)
This is a sample template code
{% for item in title %}
{{item}}
{% if not forloop.last %} | {% endif %}
{% endfor %}
This is a sample url code
(r'^now/$', current_time, link),
However, I get an error
TypeError at /now/
'function' object is not iterable
I know this works in Python. How do you iterate in django, then?
Thank you for any input in advance!
from django error page
TypeError at /now/
'function' object is not iterable
Request Method: GET Request URL: http://127.0.0.1:8000/now/ Django Version: 1.2.3 Exception Type: TypeError Exception Value:
'function' object is not iterable
Exception Location: C:\Python27\lib\site-packages\django\core\urlresolvers.py in resolve, line 121 Python Executable: C:\Python27\python.exe Python Version: 2.7.0 Python Path: ['C:\Documents and Settings\JohnWong\workspace\mysite\mysite', 'C:\Documents and Settings\JohnWong\workspace\mysite', 'C:\Python27', 'C:\Python27\DLLs', 'C:\Python27\lib', 'C:\Python27\lib\lib-tk', 'C:\Python27\lib\plat-win', 'C:\Python27\lib\site-packages', 'C:\WINDOWS\system32\python27.zip'] Server time: Sat, 16 Oct 2010 22:45:36 -0400
Environment:
Request Method: GET Request URL: http://127.0.0.1:8000/now/ Django Version: 1.2.3 Python Version: 2.7.0 Installed Applications: ['django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages'] Installed Middleware: ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware')
Traceback: File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response 91. request.path_info) File "C:\Python27\lib\site-packages\django\core\urlresolvers.py" in resolve 217. sub_match = pattern.resolve(new_path) File "C:\Python27\lib\site-packages\django\core\urlresolvers.py" in resolve 121. kwargs.update(self.default_args)
Exception Type: TypeError at /now/ Exception Value: 'function' object is not iterable