django csrf token添加

时间:2022-01-13 00:08:32
#views.py

from django.shortcuts import render_to_response, RequestContext

from django.views.decorators.csrf import csrf_protect

@csrf_protect

def index(request):

    if request.method == "GET":

        return render_to_response("index.html", context_instance=RequestContext(request))

    else:

        return render_to_response("index.html", context_instance=RequestContext(request))

  

#index.html 

<form>

{% csrf_token %}

</form>