--
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5a003506-de8d-4587-863d-3fc26e4c45c1%40googlegroups.com.
def user_register(request):
# if this is a POST request we need to process the form data
template = 'mymodule/register.html'
# template = 'index.html'
if request.method == 'POST':
# create a form instance and populate it with data from the request:
form = RegisterForm(request.POST)
# check whether it's valid:
if form.is_valid():
if User.objects.filter(username=form.cleaned_data['username']).exists():
return render(request, template, {
'form': form,
'error_message': 'Username already exists.'
})
elif User.objects.filter(email=form.cleaned_data['email']).exists():
return render(request, template, {
'form': form,
'error_message': 'Email already exists.'
})
elif form.cleaned_data['password'] != form.cleaned_data['password_repeat']:
return render(request, template, {
'form': form,
'error_message': 'Passwords do not match.'
})
else:
# Create the user:
user = User.objects.create_user(
form.cleaned_data['username'],
form.cleaned_data['email'],
form.cleaned_data['password']
)
user.first_name = form.cleaned_data['first_name']
user.last_name = form.cleaned_data['last_name']
user.phone_number = form.cleaned_data['phone_number']
user.save()
return redirect('/login/')
# Login the user
#login(request, user)
#def user_login(request):
# redirect to accounts page:
#return render(request, '/login.html')
# return HttpResponseRedirect(return, '/login.html')
# No post data availabe, let's just show the page.
else:
form = RegisterForm()
return render(request, template, {'form': form})
--
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5a003506-de8d-4587-863d-3fc26e4c45c1%40googlegroups.com.
CSRF token missing or incorrect.
request to the template's render method.{% csrf_token %} template tag inside each POST form that targets an internal URL.CsrfViewMiddleware, then you must use csrf_protect on any views that use the csrf_token template tag, as well as those that accept the POST data.DEBUG = True in your Django settings file. Change that to False, and only the initial error message will be displayed.--
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5a003506-de8d-4587-863d-3fc26e4c45c1%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/EE7F02B6-E358-4378-AD6C-255123EEE33B%40gmail.com.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5a003506-de8d-4587-863d-3fc26e4c45c1%40googlegroups.com.
--
--
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/EE7F02B6-E358-4378-AD6C-255123EEE33B%40gmail.com.
--
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a01e8d1e-7c99-4c26-a569-4ccd08daa12f%40Spark.
from django.contrib.auth.forms import UserCreationForm
def register_user(request):
if request.method == 'POST':
form = UserCreationForm(request.POST)
if form.is_valid():
form.save()
username = form.cleaned_data['username']
password = form.cleaned_data['password1']
user = authenticate(request, username=username, password=password)
login(request, user)
messages.success(request, 'registration successfull....')
return redirect('home')
else:
form = UserCreationForm()
context = {'form': form}
return render(request, 'authenticate/register.html', context)
{% extends 'authenticate/base.html' %}
{% block content %}
<h2>Registration</h2>
<form method="POST" action="{% url 'register' %}">
{% csrf_token %}
{% if form.errors %}
<p>Your form has errors, please fix</p>
{% endif %}
{{ form }}
<input type="submit" value="Register" class="btn btn-secondary">
</form>
{% endblock %}To view this discussion on the web visit https://groups.google.com/d/ msgid/django-users/EE7F02B6- E358-4378-AD6C-255123EEE33B% 40gmail.com.
--
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 view this discussion on the web visit https://groups.google.com/d/ msgid/django-users/a01e8d1e- 7c99-4c26-a569-4ccd08daa12f% 40Spark.