Add Register

This commit is contained in:
2025-01-24 17:22:27 +01:00
parent 421d287d48
commit a5adc9e27c
3 changed files with 30 additions and 4 deletions

8
core/accounts/forms.py Normal file
View File

@@ -0,0 +1,8 @@
from django import forms
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User
class RegisterForm(UserCreationForm):
class Meta:
model=User
fields = ['username','password1','password2']

View File

@@ -1,5 +1,14 @@
{% extends 'accounts/base.html' %} {% extends 'accounts/base.html' %}
{% block title %}Registrierung{% endblock %} {% block title %}Registrierung{% endblock %}
{% block content %} {% block content %}
<h2>Registrierung</h2> <header>
<h2>Registrierung</h2>
</header>
<div class="login-container">
<form method="POST" novalidate>
{% csrf_token %}
<h2>Sign Up</h2>
{{ form.as_p }}
<input type="submit" value="Register" />
</form>
{% endblock %} {% endblock %}

View File

@@ -1,10 +1,19 @@
from django.shortcuts import render from django.shortcuts import render, redirect
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from .forms import RegisterForm
# Create your views here. # Create your views here.
@login_required @login_required
def home(request): def home(request):
return render(request, 'accounts/home.html') return render(request, 'accounts/home.html')
def register(request): def register(response):
return render(request, 'accounts/register.html') if response.method == "POST":
form = RegisterForm(response.POST)
if form.is_valid():
form.save()
return redirect("home")
else:
form = RegisterForm()
return render(response, "accounts/register.html", {"form":form})