Saturday, September 17, 2016

Re: Registration form submission problem

below is also the views.py file for the registration form

def register_page(request):
if request.method=="POST":
form=RegistrationForm(request.POST)
if form.is_valid():
user=User.objects.create_user(
username=form.clean_data['username'],
password=form.clean_data['password1'],
email=form.clean_data['email']
)
return HttpResponseRedirect('/')
else:
form=RegistrationForm()
variables=RequestContext(request,{'form':form })
return render_to_response(
'registration/register.html', variables
)

On Saturday, September 17, 2016 at 9:02:52 AM UTC+1, Timothy Steele wrote:
first i created a Login form and an error message show as  CSRF token missing or incorrect.
I was able to work it out by adding {% csrf_token %} int the login form and adding the import file in the views as from django.template import Context,RequestContext.

But when i created a registration form the same problem came and i  submit the form, i added the {% csrf_token %} file in the registration form but it did not work. 
the code are shown below

{% extends "base.html" %}
{% block title %}User Registration{% endblock %}
{% block head %}User Registration{% endblock %}
{% block content %}

<form method="post" action=".">
{% csrf_token %}{{ form.as_p }}
<input type="submit" value="register" />
</form>
{% endblock %}

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5e200b47-6e50-4af2-9922-f77e79d46a74%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment