Logout/Login functionality added

This commit is contained in:
JKuijperM 2026-02-04 15:59:17 +01:00
parent 595ba93e39
commit 12cb9cafe5
5 changed files with 56 additions and 18 deletions

View File

@ -21,10 +21,25 @@ body {
font-weight: 500;
}
.nav a:hover {
.nav .nav-link {
text-decoration: none;
background-color: none;
border: none;
padding: 8px 12px;
font: inherit;
color: #333;
cursor: pointer;
}
.nav a:hover,
.nav .nav-link:hover {
text-decoration: underline;
}
.logout-form {
margin: 0;
}
.spacer {
flex: 1;
}

View File

@ -9,25 +9,30 @@
</head>
<body>
{% if user.is_authenticated %}
<header class="topbar">
<nav class="nav">
<a href="{% url 'home' %}">Home</a>
<a href="{% url 'dashboard' %}">Dashboard</a>
<a href="{% url 'expense_list' %}">Gastos</a>
<a href="{% url 'account_list' %}">Cuentas</a>
<a href="{% url 'income_list' %}">Ingresos</a>
<a href="{% url 'tag_list' %}">Etiquetas</a>
<header class="topbar">
<nav class="nav">
<a href="{% url 'home' %}">Home</a>
<a href="{% url 'dashboard' %}">Dashboard</a>
<a href="{% url 'expense_list' %}">Gastos</a>
<a href="{% url 'account_list' %}">Cuentas</a>
<a href="{% url 'income_list' %}">Ingresos</a>
<a href="{% url 'tag_list' %}">Etiquetas</a>
<span class="spacer"></span>
<span class="spacer"></span>
<span class="user">
Hola {{ request.user.username }}
</span>
<span class="user">
{{ request.user.username }}
</span>
<!-- <a href="{ url 'logout' }">Salir</a> -->
<form method="post" action="{% url 'logout' %}" class="logout-form">
{% csrf_token %}
<button type="submit" class="nav-link">Salir</button>
</form>
</nav>
</header>
</nav>
</header>
{% endif %}
<main class="content">
{% block content %}{% endblock %}

View File

@ -0,0 +1,15 @@
{% extends "expenses/base.html" %}
{% block title %}Login{% endblock %}
{% block content %}
<h2>Iniciar sesión</h2>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Entrar</button>
</form>
{% endblock %}

View File

@ -129,5 +129,6 @@ STATIC_URL = 'static/'
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
LOGIN_URL = '/admin/login/'
LOGIN_REDIRECT_URL = '/'
LOGIN_URL = 'login'
LOGIN_REDIRECT_URL = 'home'
LOGOUT_REDIRECT_URL = 'login'

View File

@ -15,9 +15,11 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.contrib.auth import urls
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('accounts/', include(urls)),
path('', include('expenses.urls')),
]