diff --git a/accounts/urls.py b/accounts/urls.py new file mode 100644 index 0000000..08bd438 --- /dev/null +++ b/accounts/urls.py @@ -0,0 +1,6 @@ +from django.urls import path +from .views import SignUpView + +urlpatterns = [ + path("signup/", SignUpView.as_view(), name="signup"), +] diff --git a/accounts/views.py b/accounts/views.py index 91ea44a..e33ab58 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -1,3 +1,10 @@ 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" diff --git a/django_customUser/settings.py b/django_customUser/settings.py index b191006..80a740e 100644 --- a/django_customUser/settings.py +++ b/django_customUser/settings.py @@ -55,7 +55,7 @@ ROOT_URLCONF = 'django_customUser.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [], + 'DIRS': [BASE_DIR / "templates"], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ @@ -122,3 +122,6 @@ STATIC_URL = 'static/' # https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' + +LOGIN_REDIRECT_URL = "home" +LOGOUT_REDIRECT_URL = "home" diff --git a/django_customUser/urls.py b/django_customUser/urls.py index ddb8083..22529f3 100644 --- a/django_customUser/urls.py +++ b/django_customUser/urls.py @@ -15,8 +15,12 @@ Including another URLconf 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin -from django.urls import path +from django.urls import path, include +from django.views.generic.base import TemplateView urlpatterns = [ + path('', TemplateView.as_view(template_name="home.html"), name="home"), path('admin/', admin.site.urls), + path('accounts/', include("accounts.urls")), + path('accounts/', include("django.contrib.auth.urls")), ] diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000..71c543f --- /dev/null +++ b/templates/base.html @@ -0,0 +1,12 @@ + + + + {% block title %}Django Auth Tutorial{% endblock %} + + +
+ {% block content %} + {% endblock %} +
+ + diff --git a/templates/home.html b/templates/home.html new file mode 100644 index 0000000..25675ce --- /dev/null +++ b/templates/home.html @@ -0,0 +1,16 @@ +{% extends "base.html" %} + +{% block title %}Home{% endblock %} + +{% block content %} +{% if user.is_authenticated %} +

Hi {{ user.username }}!

+
+ {% csrf_token %} + +
+{% else %} +

You are not logged in

+Log In | Sign Up +{% endif %} +{% endblock %} diff --git a/templates/registration/login.html b/templates/registration/login.html new file mode 100644 index 0000000..4bc3f6b --- /dev/null +++ b/templates/registration/login.html @@ -0,0 +1,12 @@ +{% extends "base.html" %} + +{% block title %}Log In{% endblock %} + +{% block content %} +

Log In

+
+ {% csrf_token %} + {{ form.as_p }} + +
+{% endblock %} diff --git a/templates/registration/signup.html b/templates/registration/signup.html new file mode 100644 index 0000000..9f656c2 --- /dev/null +++ b/templates/registration/signup.html @@ -0,0 +1,12 @@ +{% extends "base.html" %} + +{% block title %}Sign Up{% endblock %} + +{% block content %} +

Sign Up

+
+ {% csrf_token %} + {{ form.as_p }} + +
+{% endblock %}