CSRF verification failed. Request aborted

后端 未结 10 1940
执笔经年
执笔经年 2020-12-01 13:04

I try to build a very simple website where one can add data into sqlite3 database. I have a POST form with two text input.

index.html:

{% if top_list         


        
10条回答
  •  南方客
    南方客 (楼主)
    2020-12-01 13:24

    One more nicest alternative way to fix this is to use '@csrf_exempt' annotation.

    With Django 3.1.1 you could just use @csrf_exempt on your method.

    from django.views.decorators.csrf import csrf_exempt
    
    @csrf_exempt
    def index(request):
    

    and you don't need to specify {% csrf_token %} in your html.

    happy learning..

提交回复
热议问题