Django : CSRF verification failed even after adding {% csrf_token %}

后端 未结 7 1307
轻奢々
轻奢々 2021-01-03 11:20

views.py:

def index(request):
    return render_to_response(\'index.html\', {})

def photos(request, artist):
    if not artist:
        r         


        
7条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-03 11:34

    A number of things to troubleshoot here:

    • Please load your "index" page in a web browser, do "View Source", and check if the {% csrf_token %} is being expanded. It should be replaced with an tag. If that's not happening, then you have problems with your index page. If it is being replaced correctly, then you have problems with your photos page.

    • The POST URL in index.html doesn't match any of the patterns in urls.py. Your urls.py seems to expect the search term to be part of the URL, but it's not - you're sending it as a HTTP POST parameter. You need to access it via request.POST.

提交回复
热议问题