Commit 39982a74 authored by Ole Gabor Husebø's avatar Ole Gabor Husebø
Browse files

Creating User registration page. (not finished)

parent bcac9f60
{% extends 'startbase.html' %}
{% load static %}
{% load crispy_forms_tags %}
{% block body %}
<div class="content-section">
<div style="border-radius: 20px ;margin-top: 80px;width: 60%; margin-left: 20%; background-color: white; height: 450px; box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);">
<div style="border-radius: 20px ;margin-top: 80px;width: 60%; margin-left: 20%; background-color: white; height: 650px; box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);">
<form method="POST" action="{% url 'register' %}">
{% csrf_token %}
<div style="margin-left: 4%; margin-top: 10px; margin-right: 4% " >
<fieldset class = "form-group">
<legend class="border-bottom mb-4">Join Today</legend>
{{ form.as_p }}
<legend class="border-bottom mb-4">Bli Med I Dag!</legend>
{{ form|crispy }}
</fieldset>
<div class="form-group">
<button class="btn btn-outline-info" type="submit">Sign Up</button>
<button class="btn btn-outline-info" type="submit">Registrer Deg</button>
</div>
</div>
</form>
......
from django import forms
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm
class UserRegisterForm(UserCreationForm):
email = forms.EmailField()
class Meta:
model = User
fields = ['username', 'email', 'password1', 'password2']
\ No newline at end of file
from django.shortcuts import render, redirect
from django.contrib.auth.forms import UserCreationForm
from django.contrib import messages
from .forms import UserRegisterForm
def register(request):
if request.method == 'POST':
form = UserCreationForm(request.POST)
form = UserRegisterForm(request.POST)
if form.is_valid():
username = form.cleaned_data.get('username')
messages.success(request, f'Account created for {username}!')
form.save()
return redirect('startpage/')
else:
form = UserCreationForm()
form = UserRegisterForm()
return render(request, 'register.html', {'form': form})
\ No newline at end of file
......@@ -41,6 +41,7 @@ INSTALLED_APPS = [
'apps.staticpages',
'apps.feed',
'apps.users.apps.UsersConfig',
'crispy_forms',
]
MIDDLEWARE = [
......@@ -124,6 +125,8 @@ USE_TZ = True
STATIC_URL = '/static/'
CRISPY_TEMPLATE_PACK = 'bootstrap4'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static')
]
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment