Add Register
This commit is contained in:
8
core/accounts/forms.py
Normal file
8
core/accounts/forms.py
Normal 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']
|
||||||
@@ -1,5 +1,14 @@
|
|||||||
{% extends 'accounts/base.html' %}
|
{% extends 'accounts/base.html' %}
|
||||||
{% block title %}Registrierung{% endblock %}
|
{% block title %}Registrierung{% endblock %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
<header>
|
||||||
<h2>Registrierung</h2>
|
<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 %}
|
||||||
@@ -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})
|
||||||
Reference in New Issue
Block a user