Re: CSRF verification failed. Request aborted.
as Kurtis said, you need {% csrf_token %} and your rendering response should be something like this:
return render_to_response('index.html', {'your_key': your_value},context_instance=RequestContext(request)) and those your value will be rendered thru youe_key tag.
here is how your form should look like:
text = """<form method="post" action="/add/"> {% csrf_token %}
<input type="text" name="a" value="%d"> + <input type="text"
name="b" value="%d">
<input type="submit" value="="> <input type="text" value="%d">
</form>"""
name="b" value="%d">
<input type="submit" value="="> <input type="text" value="%d">
</form>"""
Am Samstag, 19. Mai 2012 04:20:39 UTC+2 schrieb plogu...@yahoo.com.cn:
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 view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/uOi0CuZcYgcJ.
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