我遇到了这个问题,但不幸的是仍然不知道如何解决它。表单完美呈现,我输入信息并收到 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 错误。此外,如果它是相关的,我将以此作为指导: