- Setup templates for login
- login page reached at accounts/login
main
Guy Davis 9 months ago
parent 429f44afe2
commit 77575c8ff4

1
.gitignore vendored

@ -1 +1,2 @@
.idea/ .idea/
db.sqlite3

@ -9,7 +9,7 @@ https://docs.djangoproject.com/en/5.0/topics/settings/
For the full list of settings and their values, see For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.0/ref/settings/ https://docs.djangoproject.com/en/5.0/ref/settings/
""" """
import os
from pathlib import Path from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'. # Build paths inside the project like this: BASE_DIR / 'subdir'.
@ -56,7 +56,9 @@ ROOT_URLCONF = 'keeppolling.urls'
TEMPLATES = [ TEMPLATES = [
{ {
'BACKEND': 'django.template.backends.django.DjangoTemplates', 'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [], 'DIRS': [
os.path.join(BASE_DIR, 'templates'),
],
'APP_DIRS': True, 'APP_DIRS': True,
'OPTIONS': { 'OPTIONS': {
'context_processors': [ 'context_processors': [
@ -131,3 +133,7 @@ STATIC_ROOT = BASE_DIR / "staticfiles"
# 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'
# Where to redirect after Login
LOGIN_REDIRECT_URL = "landing"
LOGOUT_REDIRECT_URL = "login"

@ -15,8 +15,17 @@ 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
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), path(
'admin/',
admin.site.urls,
),
path(
"accounts/",
include(
"django.contrib.auth.urls",
),
),
] ]

@ -0,0 +1,34 @@
<!DOCTYPE html>
<html lang="en">
<head>
{% block title %}
<title>Keep pollin', pollin', pollin', pollin'</title>
{% endblock %}
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Add additional CSS in static file -->
{% load static %}
<link rel="stylesheet" href="{% static 'css/style.css' %}"/>
<script
src="https://unpkg.com/htmx.org@1.9.8"
integrity="sha384-rgjA7mptc2ETQqXoYC3/zJvkU7K/aP44Y+z7xQuJiVnB/422P/Ak+F/AqFR7E4Wr"
crossorigin="anonymous"
></script>
<script src="https://unpkg.com/hyperscript.org@0.9.12"></script>
{% block extra-head %}{% endblock %}
</head>
<body>
<script>
document.body.addEventListener('htmx:configRequest', (event) => {
event.detail.headers['X-CSRFToken'] = '{{ csrf_token }}';
})
</script>
<div class="content">
{% block content %}{% endblock %}
</div>
</body>
</html>

@ -0,0 +1,43 @@
{% extends "base_template.html" %}
{% block content %}
<div>Login</div>
{% if form.errors %}
<p>Your username and password didn't match. Please try again.</p>
{% endif %}
{% if next %}
{% if user.is_authenticated %}
<p>Your account doesn't have access to this page. To proceed,
please login with an account that has access.</p>
{% else %}
<p>Please login to see this page.</p>
{% endif %}
{% endif %}
<form class="login-form"
id="login-form"
method="post"
action="{% url 'login' %}"
>
{% csrf_token %}
<div>
<div>{{ form.username.label_tag }}</div>
<div>{{ form.username }}</div>
</div>
<div>
<div>{{ form.password.label_tag }}</div>
<div>{{ form.password }}</div>
</div>
<div class="login-button"
onclick="document.forms['login-form'].submit();"
>
Login
</div>
<input type="submit" value="login" hidden="hidden">
<input type="hidden" name="next" value="{{ next }}">
</form>
{% endblock %}
Loading…
Cancel
Save

Powered by TurnKey Linux.