I am trying to save post data for a custom user registration form but I can't identify where I am going wrong. I am suspecting the problem is in mainapp/urls
. I have done some research on the subject read the following
documentation,Question on StackOverflow,Question on StackOverflow and many others but I cannot find the problem.
template
{% extends 'base.html'%}
{% load staticfiles %}
{% block content%}
{% load bootstrap %}
<div class = "signup-box">
<h2>Sign up</h2>
<form class="form-horizontal" action="signup" method="post">
{% csrf_token %}
<!-- {{ form|bootstrap }} -->
{{ form.username.label }}
{{ form.username }}
{{ form.first_name.label }}
{{ form.first_name }}
{{ form.last_name.label }}
{{ form.last_name }}
{{ form.email.label }}
{{ form.email }}
{{ form.password1.label }}
{{ form.password1 }}
{{ form.password2.label }}
{{ form.password2 }}<br>
<input type="submit" value="Submit" />
</form>
</div>
{% endblock %}
urls.py
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.home),
url(r'^login/$', views.login, name='login'),
url(r'^signup/$', views.signup, name='signup'),
]
Views.py
from django.shortcuts import render, redirect
from .forms import RegistrationForm
from .models import User
from django.contrib import messages
from django.http import HttpResponse
# Create your views here.
def register_page(request):
if request.method == "POST":
form = RegistrationForm(request.POST)
if form.is_valid():
form.save()
return HttpResponse('<h1>The form is valid!<h1>')
else:
form = RegistrationForm(request.POST)
args = {'form':form}
return render(request, 'signup', args)
else:
form = RegistrationForm()
return render(request, 'signup.html', {'form': form})
I get the following error after submitting the form
The current path, register_page/register_page/signup, didn't match any of these.