Registration form submission problem

28 views
Skip to first unread message

Timothy Steele

unread,
Sep 17, 2016, 4:02:52 AM9/17/16
to Django users
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 %}

Timothy Steele

unread,
Sep 17, 2016, 4:31:03 AM9/17/16
to Django users
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
)

ludovic coues

unread,
Sep 17, 2016, 6:40:12 AM9/17/16
to django...@googlegroups.com
Personally, I would look at the generated HTML for the form, to see if
anything is wrong.

https://gist.github.com/gkrnours/6461781883e6add258d6a70ea1804b0f is
how I have done a user registration view if you want to compare
> --
> 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...@googlegroups.com.
> To post to this group, send email to django...@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.



--

Cordialement, Coues Ludovic
+336 148 743 42
Reply all
Reply to author
Forward
0 new messages