Very basic profile view

This commit is contained in:
Benjamin 2022-12-26 00:12:47 +01:00
parent 2acfcb29e9
commit 3e726644ac
5 changed files with 28 additions and 1 deletions

View file

@ -100,6 +100,7 @@ AUTH_PASSWORD_VALIDATORS = [
}, },
] ]
LOGOUT_REDIRECT_URL = '/'
# Internationalization # Internationalization
# https://docs.djangoproject.com/en/4.1/topics/i18n/ # https://docs.djangoproject.com/en/4.1/topics/i18n/

View file

@ -20,5 +20,6 @@ from . import views
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('accounts/new-user/', views.new_user, name='new-user'), path('accounts/new-user/', views.new_user, name='new-user'),
path('accounts/profile/', views.profile, name='profile'),
path('accounts/', include('django.contrib.auth.urls')), path('accounts/', include('django.contrib.auth.urls')),
] ]

View file

@ -2,6 +2,7 @@ from .forms import SignupForm
from django.shortcuts import render from django.shortcuts import render
from django.urls import reverse from django.urls import reverse
from django.http.response import HttpResponseRedirect from django.http.response import HttpResponseRedirect
from django.contrib.auth.decorators import login_required
def new_user(request): def new_user(request):
if request.method == 'POST': if request.method == 'POST':
@ -14,3 +15,7 @@ def new_user(request):
form = SignupForm() form = SignupForm()
return render(request, 'registration/new-user.html', {'form': form}) return render(request, 'registration/new-user.html', {'form': form})
@login_required
def profile(request):
return render(request, 'registration/profile.html')

View file

@ -9,7 +9,8 @@
<nav> <nav>
<ul> <ul>
{% if user.is_authenticated %} {% if user.is_authenticated %}
<li><a href="#">Account</a></li> <li><a href="{% url 'profile' %}">Profile</a></li>
<li><a href="{% url 'logout' %}">Logout</a></li>
{% else %} {% else %}
<li><a href="{% url 'login' %}">Login</a></li> <li><a href="{% url 'login' %}">Login</a></li>
<li><a href="{% url 'new-user' %}">Create account</a></li> <li><a href="{% url 'new-user' %}">Create account</a></li>

View file

@ -0,0 +1,19 @@
{% extends "base_main.html" %}
{% block title %}Profile {{ user.username }}{% endblock %}
{% block main %}
<h1>Profile {{ user.username }}</h1>
<table>
<tr>
<td>Username</td>
<td>{{ user.username }}</td>
</tr>
<tr>
<td>First name</td>
<td>{{ user.first_name }}</td>
</tr>
<tr>
<td>Last name</td>
<td>{{ user.last_name }}</td>
</tr>
</table>
{% endblock %}