Friday, May 18, 2012

Re: CSRF verification failed. Request aborted.

In your template, you need to include {% csrf_token %} within your <form></form> block. Also, make sure HttpResponse works correctly with CSRF. It may, or it may not -- but I think I remember reading that you need to use the 'render' method to make that template tag work.

On Fri, May 18, 2012 at 10:20 PM, plogultech@yahoo.com.cn <plogultech@yahoo.com.cn> wrote:
I find a code, but the Django version is 0.9, I am using 1.4 and I am
a new learner, I want to run below code but report CSRF verification
failed.

from django.http import HttpResponse

text = """<form method="post" action="/add/">
   <input type="text" name="a" value="%d"> + <input type="text"
name="b" value="%d">
   <input type="submit" value="="> <input type="text" value="%d">
</form>"""

def index(request):
   if request.POST.has_key('a'):
       a = int(request.POST['a'])
       b = int(request.POST['b'])
   else:
       a = 0
       b = 0
   return HttpResponse(text % (a, b, a + b))

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate