problems with csrf_token

前端 未结 2 522
一整个雨季
一整个雨季 2021-01-22 18:31

I\'m doing wiki in django tutorial and in tutorial earlier version of django is used where csrf token is not compulsory. I\'ve added {% csrf_token %} to the form, however I\'m n

2条回答
  •  南方客
    南方客 (楼主)
    2021-01-22 19:02

    You don't need to do anything more.

    Just place {% csrf_token %} into your form and send it via POST.

    All other stuff will be done inside django.middleware.csrf.CsrfViewMiddleware.

    You should enable it in your settings.py (if you haven't done this):

    MIDDLEWARE_CLASSES += (`django.middleware.csrf.CsrfViewMiddleware`,)
    TEMPLATE_CONTEXT_PROCESSORS += (`django.core.context_processors.csrf`,)
    

    Last line is not required if you use RequestContext (not a simple Context) in your templates (Note: render_to_response() uses Context when direct_to_template() uses RequestContext)

提交回复
热议问题