Commit 5bd40b2e authored by Skia's avatar Skia
Browse files

First commit: basic users

from django.contrib import admin
from .models import User
from django.contrib.auth.forms import UserCreationForm
from .models import User
class RegisteringForm(UserCreationForm):
error_css_class = 'error'
required_css_class = 'required'
class Meta:
model = User
fields = ('username', 'email',)
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
import django.core.validators
import django.contrib.auth.models
import django.utils.timezone
class Migration(migrations.Migration):
dependencies = [
('auth', '0006_require_contenttypes_0002'),
operations = [
('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True, serialize=False)),
('password', models.CharField(max_length=128, verbose_name='password')),
('last_login', models.DateTimeField(blank=True, verbose_name='last login', null=True)),
('is_superuser', models.BooleanField(verbose_name='superuser status', default=False, help_text='Designates that this user has all permissions without explicitly assigning them.')),
('username', models.CharField(unique=True, validators=[django.core.validators.RegexValidator('^[\\w.@+-]+$', 'Enter a valid username. This value may contain only letters, numbers and @/./+/-/_ characters.', 'invalid')], verbose_name='username', max_length=30, error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 30 characters or fewer. Letters, digits and @/./+/-/_ only.')),
('first_name', models.CharField(max_length=30, blank=True, verbose_name='first name')),
('last_name', models.CharField(max_length=30, blank=True, verbose_name='last name')),
('email', models.EmailField(max_length=254, blank=True, verbose_name='email address')),
('is_staff', models.BooleanField(verbose_name='staff status', default=False, help_text='Designates whether the user can log into this admin site.')),
('is_active', models.BooleanField(verbose_name='active', default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.')),
('date_joined', models.DateTimeField(verbose_name='date joined',,
('nick_name', models.CharField(max_length=30)),
('groups', models.ManyToManyField(related_query_name='user', related_name='user_set', verbose_name='groups', to='auth.Group', blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.')),
('user_permissions', models.ManyToManyField(related_query_name='user', related_name='user_set', verbose_name='user permissions', to='auth.Permission', blank=True, help_text='Specific permissions for this user.')),
'verbose_name': 'user',
'verbose_name_plural': 'users',
'abstract': False,
('objects', django.contrib.auth.models.UserManager()),
from django.db import models
from django.contrib.auth.models import AbstractUser
import logging
class User(AbstractUser):
nick_name = models.CharField(max_length=30)
def __str__(self):
return self.get_username()
class Page:
<h1>Register a user</h1>
{% if username %}
You registered successfully, {{ username }}!
{% endif %}
<form action="{% url 'sith:register' %}" method="post">
{% csrf_token %}
{{ form }}
<li><input type="submit" value="Register!" /></li>
from django.test import TestCase
# Create your tests here.
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='core_index'),
url(r'^login$', views.login, name='login'),
url(r'^register$', views.register, name='register'),
url(r'^guy$', views.guy, name='guy'),
from django.shortcuts import render
from django.http import HttpResponse
from .models import User
from .forms import RegisteringForm
import logging
def index(request):
return HttpResponse("Hello, world. You're at the core index.")
def login(request):
return HttpResponse("Login page")
def register(request):
if request.method == 'POST':
logging.debug("Registering "+request.POST['username'])
form = RegisteringForm(request.POST)
if form.is_valid():
u = User(username=request.POST['username'], password=request.POST['password1'], email="guy@plop.guy")
return render(request, "sith/register.html", {'username': u.get_username(),
'form': RegisteringForm().as_ul()})
return render(request, "sith/register.html", {'form': form.as_ul()})
form = RegisteringForm()
return render(request, "sith/register.html", {'form': form.as_ul()})
def guy(request):
return HttpResponse("Guyuguyguygé")
File added
#!/usr/bin/env python3
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sith.settings")
from import execute_from_command_line
Django settings for sith project.
Generated by 'django-admin startproject' using Django 1.8.6.
For more information on this file, see
For the full list of settings and their values, see
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '(4sjxvhz@m5$0a$j0_pqicnc$s!vbve)z+&++m%g%bjhlz4+g2'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
# Application definition
ROOT_URLCONF = 'sith.urls'
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'context_processors': [
WSGI_APPLICATION = 'sith.wsgi.application'
# Database
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
# Internationalization
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
STATIC_URL = '/static/'
AUTH_USER_MODEL = 'core.User'
"""sith URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
Including another URLconf
1. Add an import: from blog import urls as blog_urls
2. Add a URL to urlpatterns: url(r'^blog/', include(blog_urls))
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^', include('core.urls', namespace="sith")),
url(r'^admin/', include(,
WSGI config for sith project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sith.settings")
application = get_wsgi_application()
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