registration page

This commit is contained in:
Alicja Cięciwa
2020-11-11 18:43:45 +01:00
parent 37906ae85b
commit c26db18f86
17 changed files with 87 additions and 15 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,6 +1,49 @@
from django.contrib.auth.forms import AuthenticationForm
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']
def __init__(self, *args, **kwargs):
super(RegisterForm, self).__init__(*args, **kwargs)
self.fields['username'] = forms.CharField(
widget=forms.TextInput(attrs={
'placeholder': 'Nazwa użytkownika'
}),
error_messages={
'required': 'Wpisz nazwę użytkownika',
})
self.fields['password1'] = forms.CharField(
widget=forms.PasswordInput(attrs={
'placeholder': 'Hasło'
}),
error_messages={
'required': 'Podaj hasło',
})
self.fields['password2'] = forms.CharField(
widget=forms.PasswordInput(attrs={
'placeholder': 'Powtórz hasło'
}),
error_messages={
'required': 'Podaj hasło',
})
for field in ['username', 'password1', 'password2']:
self.fields[field].help_text = None
self.fields[field].label = ''
# class LoginForm(AuthenticationForm):
# username = forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control'}))
# password = forms.CharField(widget=forms.PasswordInput(attrs={'class': 'form-control'}))

View File

@@ -1,3 +1,13 @@
from django.shortcuts import render
from django.shortcuts import render, redirect
from .forms import RegisterForm
# Create your views here.
def register(response):
if response.method == "POST":
form = RegisterForm(response.POST)
if form.is_valid():
form.save()
return redirect("/")
else:
form = RegisterForm()
return render(response, "registration/signup.html", {"form":form})