Skip to content

Commit 784fd99

Browse files
authored
Merge branch 'master' into top-python-game-engines
2 parents 854ca3a + f837e3f commit 784fd99

File tree

100 files changed

+2207
-41
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+2207
-41
lines changed

django-pagination/README.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Pagination for a User-Friendly Django App
2+
3+
This repository contains the source code for the Django project that you'll complete in Real Python's [Pagination for a User-Friendly Django App](https://realpython.com/django-pagination/).
4+
5+
## Create the Django Project
6+
7+
After you've cloned this repository and navigated into its folder, 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+
Navigate to the folder for the step that you're currently on.
22+
23+
Install the dependencies for this project if you haven't installed them yet:
24+
25+
```bash
26+
(venv) $ python -m pip install -r requirements.txt
27+
```
28+
29+
Apply the migrations for the project to build your local database:
30+
31+
```bash
32+
(venv) $ python manage.py migrate
33+
```
34+
35+
Run the Django development server:
36+
37+
```bash
38+
(venv) $ python manage.py runserver
39+
```
40+
41+
Navigate to `http://localhost:8000/all`.
42+
You should see an empty page with a _Python Keywords_ headline.
43+
44+
## Prepare the Database
45+
46+
Run the Django migrations:
47+
48+
```bash
49+
(venv) $ python manage.py migrate
50+
```
51+
52+
This will create the tables for the Python wiki project in your database.
53+
54+
## Add the Python Keywords Data
55+
56+
Enter the Django shell:
57+
58+
```bash
59+
(venv) $ python manage.py shell
60+
````
61+
62+
Add the Python keywords to your database:
63+
64+
```pycon
65+
>>> import keyword
66+
>>> from terms.models import Keyword
67+
>>> for kw in keyword.kwlist:
68+
... k = Keyword(name=kw)
69+
... k.save()
70+
...
71+
```
72+
73+
Verify that the keywords were added to your database:
74+
75+
```pycon
76+
>>> Keyword.objects.all()
77+
<QuerySet [<Keyword: False>, <Keyword: None>, '...(remaining elements truncated)...']>
78+
```
79+
80+
Run the Django development server:
81+
82+
```bash
83+
(venv) $ python manage.py runserver
84+
```
85+
86+
Navigate to `http://localhost:8000/all` to see the page with all the Python keywords.

django-pagination/manage.py

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", "pythonwiki.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-pagination/pythonwiki/__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 pythonwiki 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/4.0/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", "pythonwiki.settings")
15+
16+
application = get_asgi_application()
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
"""
2+
Django settings for pythonwiki project.
3+
4+
Generated by 'django-admin startproject' using Django 4.0.1.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/4.0/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/4.0/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/4.0/howto/deployment/checklist/
21+
22+
# SECURITY WARNING: keep the secret key used in production secret!
23+
SECRET_KEY = (
24+
"django-insecure-oaz&b2n60j$^dtundsvk$f^iobo4&@zkn6j7u*ac)y0%7ty863"
25+
)
26+
27+
# SECURITY WARNING: don't run with debug turned on in production!
28+
DEBUG = True
29+
30+
ALLOWED_HOSTS = []
31+
32+
33+
# Application definition
34+
35+
INSTALLED_APPS = [
36+
"django.contrib.admin",
37+
"django.contrib.auth",
38+
"django.contrib.contenttypes",
39+
"django.contrib.sessions",
40+
"django.contrib.messages",
41+
"django.contrib.staticfiles",
42+
"terms",
43+
]
44+
45+
MIDDLEWARE = [
46+
"django.middleware.security.SecurityMiddleware",
47+
"django.contrib.sessions.middleware.SessionMiddleware",
48+
"django.middleware.common.CommonMiddleware",
49+
"django.middleware.csrf.CsrfViewMiddleware",
50+
"django.contrib.auth.middleware.AuthenticationMiddleware",
51+
"django.contrib.messages.middleware.MessageMiddleware",
52+
"django.middleware.clickjacking.XFrameOptionsMiddleware",
53+
]
54+
55+
ROOT_URLCONF = "pythonwiki.urls"
56+
57+
TEMPLATES = [
58+
{
59+
"BACKEND": "django.template.backends.django.DjangoTemplates",
60+
"DIRS": [],
61+
"APP_DIRS": True,
62+
"OPTIONS": {
63+
"context_processors": [
64+
"django.template.context_processors.debug",
65+
"django.template.context_processors.request",
66+
"django.contrib.auth.context_processors.auth",
67+
"django.contrib.messages.context_processors.messages",
68+
],
69+
},
70+
},
71+
]
72+
73+
WSGI_APPLICATION = "pythonwiki.wsgi.application"
74+
75+
# Database
76+
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases
77+
78+
DATABASES = {
79+
"default": {
80+
"ENGINE": "django.db.backends.sqlite3",
81+
"NAME": BASE_DIR / "db.sqlite3",
82+
}
83+
}
84+
85+
86+
# Password validation
87+
# https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators
88+
89+
AUTH_PASSWORD_VALIDATORS = [
90+
{
91+
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
92+
},
93+
{
94+
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
95+
},
96+
{
97+
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
98+
},
99+
{
100+
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
101+
},
102+
]
103+
104+
105+
# Internationalization
106+
# https://docs.djangoproject.com/en/4.0/topics/i18n/
107+
108+
LANGUAGE_CODE = "en-us"
109+
110+
TIME_ZONE = "UTC"
111+
112+
USE_I18N = True
113+
114+
USE_TZ = True
115+
116+
117+
# Static files (CSS, JavaScript, Images)
118+
# https://docs.djangoproject.com/en/4.0/howto/static-files/
119+
120+
STATIC_URL = "static/"
121+
122+
# Default primary key field type
123+
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
124+
125+
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 path, include
3+
4+
urlpatterns = [
5+
path("admin/", admin.site.urls),
6+
path("", include("terms.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 pythonwiki 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/4.0/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", "pythonwiki.settings")
15+
16+
application = get_wsgi_application()

django-pagination/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
django==4.0.1

django-pagination/terms/__init__.py

Whitespace-only changes.

django-pagination/terms/admin.py

Whitespace-only changes.

0 commit comments

Comments
 (0)