문제

I have an issue with the {% csrf_token %} template tag in Django. On pages loaded via get it is fine but if I use post to load a page the tag is not loaded to forms on the page requested with post.

I am using render_to_response to render the pages

Any ideas?

Thanks

도움이 되었습니까?

해결책

Are you updating your context with the csrf token when calling render_to_response from a POST request? Like so:

from django.core.context_processors import csrf
from django.shortcuts import render_to_response

def my_view(request):
    if request.method == 'POST':
        c = {}
        c.update(csrf(request))
        return render_to_response("a_template.html", c)
    else:
        # GET code...
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top