In views.py snippet of Code

171 views
Skip to first unread message

Django_for_SB

unread,
Mar 15, 2012, 2:32:53 PM3/15/12
to Django users
Hi All,

I'm using render_to_response() in my views.py module. And of course,
I've imported the method:

"from django.shortcuts import render_to_response"

# This is the code that's generating the error:
def hours_ahead(request, offset):
try:
offset = int(offset)
except ValueError:
raise Http404()
dt = datetime.datetime.now() + datetime.timedelta(hours =
offset)
return render_to_response('hours_ahead.html', {'hour_offset':
offset}, {'next_time': dt})


Django is complaining that my "render_to_response()" statement is
wrong with the following debug statement:

"pop expected at least 1 arguments, got 0"

Here is the full traceback:


Traceback:
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in
get_response
111. response = callback(request,
*callback_args, **callback_kwargs)
File "C:\Python27\my_Djando_projects\HelloWorld\..\HelloWorld
\views.py" in hours_ahead
31. return render_to_response('hours_ahead.html',
{'hour_offset': offset}, {'next_time': dt})
File "C:\Python27\lib\site-packages\django\shortcuts\__init__.py" in
render_to_response
20. return HttpResponse(loader.render_to_string(*args,
**kwargs), **httpresponse_kwargs)
File "C:\Python27\lib\site-packages\django\template\loader.py" in
render_to_string
190. context_instance.pop()

Exception Type: TypeError at /time/plus/3/
Exception Value: pop expected at least 1 arguments, got 0






Since I'm still fairly new to Django, I can't quite see what I'm doing
incorrectly here. Any assistance would be greatly appreciated. Thank
you.

Best,

SB

Kevin Wetzels

unread,
Mar 15, 2012, 2:43:24 PM3/15/12
to django...@googlegroups.com

You're passing in three parameters to render_to_response. The third one is expected to be an instance of Context (see https://docs.djangoproject.com/en/dev/topics/http/shortcuts/#django.shortcuts.render_to_response), but you're passing in a dictionary.

render_to_response('hours_ahead.html', {'hour_offset': offset, 'next_time': dt}) is what you want.

Sami Balbaky

unread,
Mar 15, 2012, 4:40:24 PM3/15/12
to django...@googlegroups.com
Thank you Kevin, problem solved. I'm actually reading the book from www.djangobook.com. I need to cross reference with the documentation on www.thedjangoproject.com.

Best,

SB

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/2Oq52gruh2cJ.

To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



--
Sami Balbaky
System Engineer - Ultrawave Labs

Reply all
Reply to author
Forward
0 new messages