Skip to content

Commit 2ace37c

Browse files
authored
Merge pull request #618 from realpython/django-user-management
Add Django User Management files
2 parents b5911a2 + 7a671e4 commit 2ace37c

28 files changed

+385
-0
lines changed

django-user-management/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Get Started With Django User Management
2+
3+
Follow the [step-by-step instructions](https://realpython.com/django-user-management/) on Real Python.
4+
5+
## Setup
6+
7+
You can run the provided example project on your local machine by following the steps outlined below.
8+
9+
Create a new virtual environment:
10+
11+
```bash
12+
$ python3 -m venv venv/
13+
```
14+
15+
Activate the virtual environment:
16+
17+
```bash
18+
$ source venv/bin/activate
19+
```
20+
21+
Install the dependencies for this project if you haven't installed them yet:
22+
23+
```bash
24+
(venv) $ python -m pip install -r requirements.txt
25+
```
26+
27+
Navigate into the project's directory:
28+
29+
```bash
30+
(venv) $ cd user_auth_intro/
31+
```
32+
33+
Make and apply the migrations for the project to build your local database:
34+
35+
```bash
36+
(venv) $ python manage.py makemigrations
37+
(venv) $ python manage.py migrate
38+
```
39+
40+
Run the Django development server:
41+
42+
```bash
43+
(venv) $ python manage.py runserver
44+
```
45+
46+
Navigate to `http://localhost:8000/dashboard` to see the project in action.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
asgiref==3.8.1
2+
Django==5.1.3
3+
sqlparse==0.5.2
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
"""Django's command-line utility for administrative tasks."""
3+
import os
4+
import sys
5+
6+
7+
def main():
8+
"""Run administrative tasks."""
9+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "user_auth_intro.settings")
10+
try:
11+
from django.core.management import execute_from_command_line
12+
except ImportError as exc:
13+
raise ImportError(
14+
"Couldn't import Django. Are you sure it's installed and "
15+
"available on your PYTHONPATH environment variable? Did you "
16+
"forget to activate a virtual environment?"
17+
) from exc
18+
execute_from_command_line(sys.argv)
19+
20+
21+
if __name__ == "__main__":
22+
main()

django-user-management/user_auth_intro/user_auth_intro/__init__.py

Whitespace-only changes.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
ASGI config for user_auth_intro project.
3+
4+
It exposes the ASGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/5.1/howto/deployment/asgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.asgi import get_asgi_application
13+
14+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "user_auth_intro.settings")
15+
16+
application = get_asgi_application()
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
"""
2+
Django settings for user_auth_intro project.
3+
4+
Generated by 'django-admin startproject' using Django 5.1.3.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/5.1/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/5.1/ref/settings/
11+
"""
12+
13+
from pathlib import Path
14+
15+
# Build paths inside the project like this: BASE_DIR / 'subdir'.
16+
BASE_DIR = Path(__file__).resolve().parent.parent
17+
18+
19+
# Quick-start development settings - unsuitable for production
20+
# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/
21+
22+
# SECURITY WARNING: keep the secret key used in production secret!
23+
SECRET_KEY = (
24+
"django-insecure-%&$tji0geb7vpx8@9-&qbf3_%3$s=5*5amo4tr)yg!6&6@bbhl"
25+
)
26+
27+
# SECURITY WARNING: don't run with debug turned on in production!
28+
DEBUG = True
29+
30+
ALLOWED_HOSTS = []
31+
32+
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
33+
34+
35+
# Application definition
36+
37+
INSTALLED_APPS = [
38+
"users.apps.UsersConfig",
39+
"django.contrib.admin",
40+
"django.contrib.auth",
41+
"django.contrib.contenttypes",
42+
"django.contrib.sessions",
43+
"django.contrib.messages",
44+
"django.contrib.staticfiles",
45+
]
46+
47+
MIDDLEWARE = [
48+
"django.middleware.security.SecurityMiddleware",
49+
"django.contrib.sessions.middleware.SessionMiddleware",
50+
"django.middleware.common.CommonMiddleware",
51+
"django.middleware.csrf.CsrfViewMiddleware",
52+
"django.contrib.auth.middleware.AuthenticationMiddleware",
53+
"django.contrib.messages.middleware.MessageMiddleware",
54+
"django.middleware.clickjacking.XFrameOptionsMiddleware",
55+
]
56+
57+
ROOT_URLCONF = "user_auth_intro.urls"
58+
59+
TEMPLATES = [
60+
{
61+
"BACKEND": "django.template.backends.django.DjangoTemplates",
62+
"DIRS": [],
63+
"APP_DIRS": True,
64+
"OPTIONS": {
65+
"context_processors": [
66+
"django.template.context_processors.debug",
67+
"django.template.context_processors.request",
68+
"django.contrib.auth.context_processors.auth",
69+
"django.contrib.messages.context_processors.messages",
70+
],
71+
},
72+
},
73+
]
74+
75+
WSGI_APPLICATION = "user_auth_intro.wsgi.application"
76+
77+
78+
# Database
79+
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases
80+
81+
DATABASES = {
82+
"default": {
83+
"ENGINE": "django.db.backends.sqlite3",
84+
"NAME": BASE_DIR / "db.sqlite3",
85+
}
86+
}
87+
88+
89+
# Password validation
90+
# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators
91+
92+
AUTH_PASSWORD_VALIDATORS = [
93+
{
94+
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
95+
},
96+
{
97+
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
98+
},
99+
{
100+
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
101+
},
102+
{
103+
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
104+
},
105+
]
106+
107+
108+
# Internationalization
109+
# https://docs.djangoproject.com/en/5.1/topics/i18n/
110+
111+
LANGUAGE_CODE = "en-us"
112+
113+
TIME_ZONE = "UTC"
114+
115+
USE_I18N = True
116+
117+
USE_TZ = True
118+
119+
120+
# Static files (CSS, JavaScript, Images)
121+
# https://docs.djangoproject.com/en/5.1/howto/static-files/
122+
123+
STATIC_URL = "static/"
124+
125+
# Default primary key field type
126+
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
127+
128+
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from django.contrib import admin
2+
from django.urls import include, path
3+
4+
urlpatterns = [
5+
path("", include("users.urls")),
6+
path("admin/", admin.site.urls),
7+
]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
WSGI config for user_auth_intro project.
3+
4+
It exposes the WSGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/5.1/howto/deployment/wsgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.wsgi import get_wsgi_application
13+
14+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "user_auth_intro.settings")
15+
16+
application = get_wsgi_application()

django-user-management/user_auth_intro/users/__init__.py

Whitespace-only changes.

django-user-management/user_auth_intro/users/admin.py

Whitespace-only changes.

0 commit comments

Comments
 (0)