POST method always return 403 Forbidden

前端 未结 7 1651
走了就别回头了
走了就别回头了 2021-02-19 01:46

I have read Django - CSRF verification failed and several questions (and answers) related to django and POST method. One of the best-but-not-working-for-me answer is https://sta

7条回答
  •  [愿得一人]
    2021-02-19 02:12

    The easiest way to avoid such problems is to use the render shortcut.

    from django.shortcuts import render
    # .. your other imports
    
    def search_form(request):
        return render(request, 'library/search_form.html')
    
    def search(request):
        q = request.GET.get('q')
        results = BookModel.objects.all()
        if q:
            results = results.filter(title__icontains=q)
        return render(request, 'library/search.html', {'result': results})
    

提交回复
热议问题