Re: hi [django-users] How to do something after "return HttpResponse(html)"?
The question is: What you're trying to do?
1. You can do any other process before the return line, the return will be the same... for example:
from django.http import HttpResponse
from datetime import datetime
def current_datetime(request):
now = datetime.now()
html = "<html><body>It is now %s.</body></html>" % now
year = now.year()
return HttpResponse(html)
2. You can use a conditional to have multiple returns:
from django.http import HttpResponse
from datetime import datetime
def current_datetime(request):
now = datetime.now()
html = "<html><body>It is now %s.</body></html>" % now
year = now.year()
if year == 2013:
return HttpResponse(html)
else:
return HttpResponse(<html><body>Sorry it's not 2013.</body></html>")
2013/6/25 Timster <timshaffer00@gmail.com>
You cannot do something after the "return" line. This is Python functionality. When you return, the function exits and does not process anything else.
What exactly are you trying to do? There is probably another way to accomplish it.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home