Django version 1.11.5,
views.py
class SignupPage(CreateView):
form_class = forms.UserSignupForm
success_url = reverse_lazy('login')
template_name = 'signup.html'
website/urls.py
from django.conf.urls import url
from django.contrib.auth import views as auth_views
from django.contrib.auth.views import LoginView,LogoutView
from . import views
app_name = 'website'
urlpatterns = [
url(r'^login/', auth_views.LoginView.as_view(template_name='signin_2_w.html'), name='login'),
url(r'^logout/$', auth_views.LogoutView.as_view(), name='logout'),
url(r'^signup/', views.SignupPage.as_view(), name='sign_up'),
forms.py
class UserSignupForm(UserCreationForm):
class Meta:
fields = ('username','email','password1','password2')
model = get_user_model()
def __init__(self,*args,**kwargs):
super().__init__(*args,**kwargs)
self.fields['username'].label = "Display Name"
self.fields['email'].label = "Email Address"
self.fields['password1'].label = "Password"
self.fields['password2'].label = "Confirm Password"
proj/urls.py
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$',views.HomePage.as_view(),name='home'),
url(r'^website/',include('website.urls',namespace='website')),
url(r'^website/',include('django.contrib.auth.urls')),
url(r'^website/',views.StreamyePage.as_view(),name='streamye'),
url(r'^thanks/$',views.ThanksPage.as_view(),name='thanks'),
url(r'^congrats/$',views.CongratsPage.as_view(),name='congrats'),
url(r'^aboutus/$',views.AboutusPage.as_view(),name='about_us'),
HTML
<ul class="nav navbar-nav navbar-right">
{% if user.is_authenticated %}
<li><a href="{% url 'logout' %}">Logout</a></li>
{% else %}
<li><a href="{% url 'login' %}">Login</a></li>
<li><a href="{% url 'sign_up' %}">Signup</a></li>
{% endif %}
</ul>
In the above code, the signup page is throwing me a error -- "django.urls.exceptions.NoReverseMatch: Reverse for 'sign_up' not found. 'sign_up' is not a valid view function or pattern name."
Please someone help me out where im wrong! Thanks in advance!
You have to fix the links in the template to target the website
urls :
{% if user.is_authenticated %}
<li><a href="{% url 'website:logout' %}">Logout</a></li>
{% else %}
<li><a href="{% url 'website:login' %}">Login</a></li>
<li><a href="{% url 'website:sign_up' %}">Signup</a></li>
{% endif %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With