gpt4 book ai didi

Django 403 CSRF token 丢失或不正确

转载 作者:行者123 更新时间:2023-12-01 02:23:49 24 4
gpt4 key购买 nike

我遇到过这个问题,但不幸的是仍然不知道如何解决它。表单呈现完美,我输入信息并收到 CSRF 错误。给出的原因是 token missing or incorrect .

看法:

def eventSell(request, id):
c = {}
c.update(csrf(request))
event = SquidEvent.objects.get(pk = id)
listing_form = ListingForm(request.POST)
if request.user.is_authenticated():
if request.method == 'POST':
listing_form = ListingForm(request.POST)
if listing_form.is_valid():
cd = listing_form.cleaned_data
user = request.user
item = Object(price = cd['price'], seller = user)
item.save()
return HttpResponseRedirect(reverse('tixeng:index'), c)
#print listing_form
else:
return render_to_response('tixeng/list.html', {'event' : event, 'form' : listing_form}, c)
else:
return HttpResponseRedirect(reverse('allauth.account.views.login'))

这是我的模板:
<form action="{% url 'app:eventSell' event.id %}" method="post">
{% csrf_token %}
{{ form }}
<input type="submit" value="Submit">
</form>

我想我已经做对了一切,我不确定是什么导致了 CSRF 错误。此外,如果与此相关,我将其作为指南:

http://www.djangobook.com/en/2.0/chapter07.html

最佳答案

这里的堆栈Django "The view didn't return an HttpResponse object."能够帮我解决问题。一旦我添加 context_instance = RequestContext(request)到我的 render_to_response有效。

关于Django 403 CSRF token 丢失或不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18221980/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com