Add signup and login pages
This commit is contained in:
parent
3b0746ed83
commit
589d109cec
6
accounts/urls.py
Normal file
6
accounts/urls.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
from django.urls import path
|
||||||
|
from .views import SignUpView
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path("signup/", SignUpView.as_view(), name="signup"),
|
||||||
|
]
|
||||||
@ -1,3 +1,10 @@
|
|||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
|
from django.urls import reverse_lazy
|
||||||
|
from django.views.generic.edit import CreateView
|
||||||
|
|
||||||
# Create your views here.
|
from .forms import CustomUserCreationForm
|
||||||
|
|
||||||
|
class SignUpView(CreateView):
|
||||||
|
form_class = CustomUserCreationForm
|
||||||
|
sucess_url = reverse_lazy("login")
|
||||||
|
template_name = "registration/signup.html"
|
||||||
|
|||||||
@ -55,7 +55,7 @@ ROOT_URLCONF = 'django_customUser.urls'
|
|||||||
TEMPLATES = [
|
TEMPLATES = [
|
||||||
{
|
{
|
||||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||||
'DIRS': [],
|
'DIRS': [BASE_DIR / "templates"],
|
||||||
'APP_DIRS': True,
|
'APP_DIRS': True,
|
||||||
'OPTIONS': {
|
'OPTIONS': {
|
||||||
'context_processors': [
|
'context_processors': [
|
||||||
@ -122,3 +122,6 @@ STATIC_URL = 'static/'
|
|||||||
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field
|
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field
|
||||||
|
|
||||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||||
|
|
||||||
|
LOGIN_REDIRECT_URL = "home"
|
||||||
|
LOGOUT_REDIRECT_URL = "home"
|
||||||
|
|||||||
@ -15,8 +15,12 @@ Including another URLconf
|
|||||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||||
"""
|
"""
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path
|
from django.urls import path, include
|
||||||
|
from django.views.generic.base import TemplateView
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
|
path('', TemplateView.as_view(template_name="home.html"), name="home"),
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
|
path('accounts/', include("accounts.urls")),
|
||||||
|
path('accounts/', include("django.contrib.auth.urls")),
|
||||||
]
|
]
|
||||||
|
|||||||
12
templates/base.html
Normal file
12
templates/base.html
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>{% block title %}Django Auth Tutorial{% endblock %}</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<main>
|
||||||
|
{% block content %}
|
||||||
|
{% endblock %}
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
16
templates/home.html
Normal file
16
templates/home.html
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block title %}Home{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
{% if user.is_authenticated %}
|
||||||
|
<h2>Hi {{ user.username }}!</h2>
|
||||||
|
<form action="{% url 'logout' %}" method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
<button type="submit">Log Out</button>
|
||||||
|
</form>
|
||||||
|
{% else %}
|
||||||
|
<p>You are not logged in</p>
|
||||||
|
<a href="{% url 'login' %}">Log In</a> | <a href="{% url 'signup' %}">Sign Up</a>
|
||||||
|
{% endif %}
|
||||||
|
{% endblock %}
|
||||||
12
templates/registration/login.html
Normal file
12
templates/registration/login.html
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block title %}Log In{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h2>Log In</h2>
|
||||||
|
<form method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ form.as_p }}
|
||||||
|
<button type="submit">Log In</button>
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
||||||
12
templates/registration/signup.html
Normal file
12
templates/registration/signup.html
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block title %}Sign Up{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h2>Sign Up</h2>
|
||||||
|
<form method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ form.as_p }}
|
||||||
|
<button type="submit">Sign Up</button>
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
||||||
Loading…
x
Reference in New Issue
Block a user