If I include {% csrf_token%}
in my form template and import RequestContext in my view,
do I have to include anything else in my view or will the csrf protection be taken care of just be the following:
from django.shortcuts import render_to_response
from django import forms
from django.http import HttpResponseRedirect
from django.template import Template, RequestContext
from dash.forms import GradeForm
def register(request):
if request.method == 'POST':
form = GradeForm(data=request.POST)
if form.is_valid():
new_dash_profile = form.save()
new_user = form.save()
return HttpResponseRedirect("/success/")
else:
form = RegisterForm()
return render_to_response('grade.html',{'form':form})
To me, the easiest way is to add a RequestContext to the render_to_response function
return render_to_response('grade.html',
{'form':form},
context_instance=RequestContext(request))
This is just one possibility, the important thing is that you should process the csrf token somewhere, and RequestContext does that.
An other possibility is to do ir manually:
from django.template.context_processors import csrf
params = {}
params.update(csrf(request))
return render_to_response('grade.html', params)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With