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' %} {% extends 'startbase.html' %}
{% load static %} {% load static %}
{% load crispy_forms_tags %}
{% block body %} {% block body %}
<div class="content-section"> <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' %}"> <form method="POST" action="{% url 'register' %}">
{% csrf_token %} {% csrf_token %}
<div style="margin-left: 4%; margin-top: 10px; margin-right: 4% " > <div style="margin-left: 4%; margin-top: 10px; margin-right: 4% " >
<fieldset class = "form-group"> <fieldset class = "form-group">
<legend class="border-bottom mb-4">Join Today</legend> <legend class="border-bottom mb-4">Bli Med I Dag!</legend>
{{ form.as_p }} {{ form|crispy }}
</fieldset> </fieldset>
<div class="form-group"> <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>
</div> </div>
</form> </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.shortcuts import render, redirect
from django.contrib.auth.forms import UserCreationForm
from django.contrib import messages from django.contrib import messages
from .forms import UserRegisterForm
def register(request): def register(request):
if request.method == 'POST': if request.method == 'POST':
form = UserCreationForm(request.POST) form = UserRegisterForm(request.POST)
if form.is_valid(): if form.is_valid():
username = form.cleaned_data.get('username') username = form.cleaned_data.get('username')
messages.success(request, f'Account created for {username}!') messages.success(request, f'Account created for {username}!')
form.save() form.save()
return redirect('startpage/') return redirect('startpage/')
else: else:
form = UserCreationForm() form = UserRegisterForm()
return render(request, 'register.html', {'form': form}) return render(request, 'register.html', {'form': form})
\ No newline at end of file
...@@ -41,6 +41,7 @@ INSTALLED_APPS = [ ...@@ -41,6 +41,7 @@ INSTALLED_APPS = [
'apps.staticpages', 'apps.staticpages',
'apps.feed', 'apps.feed',
'apps.users.apps.UsersConfig', 'apps.users.apps.UsersConfig',
'crispy_forms',
] ]
MIDDLEWARE = [ MIDDLEWARE = [
...@@ -124,6 +125,8 @@ USE_TZ = True ...@@ -124,6 +125,8 @@ USE_TZ = True
STATIC_URL = '/static/' STATIC_URL = '/static/'
CRISPY_TEMPLATE_PACK = 'bootstrap4'
STATICFILES_DIRS = [ STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static') 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