मैं अपनी साइट के लिए लॉगिन का एहसास करना चाहता हूं। मैंने मूल रूप से Django बुक से निम्नलिखित बिट्स की प्रतिलिपि बनाई और चिपकाया। हालांकि मुझे अभी भी एक त्रुटि मिल रही है (सीएसआरएफ सत्यापन विफल रहा। अनुरोध निरस्त कर दिया गया।), मेरे पंजीकरण फॉर्म जमा करते समय। क्या कोई मुझे बता सकता है कि इस त्रुटि को किसने उठाया और इसे कैसे ठीक किया जाए?dsango में csrf त्रुटि
यहाँ मेरी कोड है:
views.py:
# Create your views here.
from django import forms
from django.contrib.auth.forms import UserCreationForm
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
def register(request):
if request.method == 'POST':
form = UserCreationForm(request.POST)
if form.is_valid():
new_user = form.save()
return HttpResponseRedirect("/books/")
else:
form = UserCreationForm()
return render_to_response("registration/register.html", {
'form': form,
})
register.html:
<html>
<body>
{% block title %}Create an account{% endblock %}
{% block content %}
<h1>Create an account</h1>
<form action="" method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Create the account">
</form>
{% endblock %}
</body>
</html>
वर्तमान django के साथ, बेहतर समाधान render_to_response() के बजाय रेंडर() का उपयोग करना होगा। –