Add page showing account info

Co-authored-by: lois <lois@procolix.eu>
Co-authored-by: Kiara Grouwstra <kiara.grouwstra@gmail.com>
This commit is contained in:
Kevin Muller 2025-02-18 15:06:47 +01:00 committed by Valentin Gagarin
parent d5632a795b
commit ac2b544a9a
7 changed files with 37 additions and 3 deletions

View file

@ -2,6 +2,7 @@
lib,
buildPythonPackage,
setuptools,
sqlite,
django_4,
django-compressor,
django-libsass,
@ -46,6 +47,7 @@ buildPythonPackage {
django-compressor
django-libsass
dj-database-url
sqlite
];
postInstall = ''

View file

@ -119,6 +119,9 @@ AUTH_PASSWORD_VALIDATORS = [
},
]
LOGIN_URL = 'login'
LOGIN_REDIRECT_URL = '/' # Redirect to homepage after login
LOGOUT_REDIRECT_URL = '/' # Redirect to homepage after logout
# Internationalization
# https://docs.djangoproject.com/en/4.2/topics/i18n/

View file

@ -0,0 +1,8 @@
{% extends "base.html" %}
{% block content %}
<h1>{{ user.username }}</h1>
<dl>
<dt>e-mail</dt><dd>{{ user.email}}</dd>
</dl>
{% endblock %}

View file

@ -17,9 +17,9 @@
<body>
<header>
{% if user.is_authenticated %}
<p>Welcome, {{ user.username }}!</p>
<p>Welcome, {{ user.username }}! <a href="{% url 'logout' %}">Logout</a></p>
{% else %}
<p>You are not logged in.</p>
<p><a href="{% url 'login' %}">Login</a></p>
{% endif %}
</header>
{% block navigation %}

View file

@ -0,0 +1,10 @@
{% extends 'base.html' %}
{% block content %}
<h2>Login</h2>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Login</button>
</form>
{% endblock %}

View file

@ -15,10 +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 include, path
from panel import views
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.Index.as_view(), name='index'),
path("", include("django.contrib.auth.urls")),
path("account/", views.AccountDetail.as_view(), name='accountdetail')
]

View file

@ -1,4 +1,13 @@
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.models import User
from django.views.generic import TemplateView
from django.views.generic import DetailView
class Index(TemplateView):
template_name = 'index.html'
class AccountDetail(LoginRequiredMixin, DetailView):
model = User
template_name = 'accountdetail.html'
def get_object(self):
return self.request.user