Skip to content

Commit 0d0d7ec

Browse files
authored
Merge pull request #1377 from PokeAPI/django5
Upgrade to django 5
2 parents ce5388c + 50a024c commit 0d0d7ec

7 files changed

Lines changed: 34 additions & 53 deletions

File tree

config/docker-compose.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
DATABASES = {
66
"default": {
7-
"ENGINE": "django.db.backends.postgresql_psycopg2",
7+
"ENGINE": "django.db.backends.postgresql",
88
"NAME": os.environ.get("POSTGRES_DB", "pokeapi"),
99
"USER": os.environ.get("POSTGRES_USER", "ash"),
1010
"PASSWORD": os.environ.get("POSTGRES_PASSWORD", "pokemon"),
@@ -23,6 +23,4 @@
2323
}
2424
}
2525

26-
DEBUG = False
27-
2826
ALLOWED_HOSTS = ["*"]

config/docker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
DATABASES = {
55
"default": {
6-
"ENGINE": "django.db.backends.postgresql_psycopg2",
6+
"ENGINE": "django.db.backends.postgresql",
77
"NAME": "pokeapi",
88
"USER": "ash",
99
"PASSWORD": "pokemon",

config/local.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
DATABASES = {
44
"default": {
55
"ENGINE": "django.db.backends.sqlite3",
6-
"NAME": os.path.join(PROJECT_ROOT, "db.sqlite3"),
6+
"NAME": BASE_DIR / "db.sqlite3",
77
}
88
}
99

config/settings.py

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,30 @@
11
# Production settings
22
import os
3-
from unipath import Path
3+
from pathlib import Path
44

5-
PROJECT_ROOT = Path(__file__).ancestor(2)
5+
BASE_DIR = Path(__file__).resolve().parent.parent
66

77
DEBUG = False
88

99
TEMPLATE_DEBUG = DEBUG
1010

11-
ADMINS = (
12-
os.environ.get("ADMINS", "Paul Hallett,paulandrewhallett@gmail.com").split(","),
13-
)
11+
ADMINS = (os.environ.get("ADMINS", "admin,admin@noemail.com").split(","),)
1412

1513
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
1614

1715
MANAGERS = ADMINS
1816

1917
BASE_URL = os.environ.get("BASE_URL", "http://pokeapi.co")
2018

21-
# Hosts/domain names that are valid for this site; required if DEBUG is False
22-
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
2319
ALLOWED_HOSTS = [
2420
os.environ.get("ALLOWED_HOSTS", ".pokeapi.co"),
2521
"localhost",
2622
"127.0.0.1",
2723
]
2824

29-
TIME_ZONE = os.environ.get("TIME_ZONE", "Europe/London")
25+
TIME_ZONE = os.environ.get("TIME_ZONE", "UTC")
3026

31-
LANGUAGE_CODE = os.environ.get("LANGUAGE_CODE", "en-gb")
27+
LANGUAGE_CODE = os.environ.get("LANGUAGE_CODE", "en-us")
3228

3329
SITE_ID = 1
3430

@@ -82,28 +78,23 @@
8278
}
8379

8480
SECRET_KEY = os.environ.get(
85-
"SECRET_KEY", "ubx+22!jbo(^x2_scm-o$*py3e@-awu-n^hipkm%2l$sw$&2l#"
81+
"SECRET_KEY", "django-insecure-a(!_5+l3$#l1f4n!x+&ns_+8$4q@df*3rh$n#2h@l$2gti7!7-"
8682
)
8783

8884
CUSTOM_APPS = ("pokemon_v2",)
8985

9086
INSTALLED_APPS = (
87+
"django.contrib.admin",
9188
"django.contrib.auth",
9289
"django.contrib.contenttypes",
9390
"django.contrib.sessions",
94-
"django.contrib.sites",
95-
"django.contrib.admin",
9691
"django.contrib.messages",
97-
"django.contrib.humanize",
9892
"corsheaders",
9993
"rest_framework",
10094
"cachalot",
10195
"drf_spectacular",
10296
) + CUSTOM_APPS
10397

104-
105-
API_LIMIT_PER_PAGE = 1
106-
10798
CORS_ORIGIN_ALLOW_ALL = True
10899

109100
CORS_ALLOW_METHODS = "GET"
@@ -127,7 +118,6 @@
127118
"APP_DIRS": True,
128119
"OPTIONS": {
129120
"context_processors": [
130-
"django.template.context_processors.debug",
131121
"django.template.context_processors.request",
132122
"django.contrib.auth.context_processors.auth",
133123
"django.contrib.messages.context_processors.messages",
@@ -136,7 +126,7 @@
136126
},
137127
]
138128

139-
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
129+
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
140130

141131
SPECTACULAR_SETTINGS = {
142132
"TITLE": "PokéAPI",
@@ -154,7 +144,7 @@
154144
155145
This API will always be publicly available and will never require any extensive setup process to consume.
156146
157-
Created by [**Paul Hallett**](https://github.com/phalt) and other [**PokéAPI contributors***](https://github.com/PokeAPI/pokeapi#contributing) around the world. Pokémon and Pokémon character names are trademarks of Nintendo.
147+
Created by [**Paul Hallett**](https://github.com/phalt) and other [**PokéAPI contributors**](https://github.com/PokeAPI/pokeapi#contributing) around the world. Pokémon and Pokémon character names are trademarks of Nintendo.
158148
""",
159149
"SORT_OPERATIONS": False,
160150
"SERVERS": [{"url": "https://pokeapi.co"}],

config/wsgi.py

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,16 @@
11
"""
2-
WSGI config for project.
2+
WSGI config for mysite project.
33
4-
This module contains the WSGI application used by Django's development server
5-
and any production WSGI deployments. It should expose a module-level variable
6-
named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
7-
this application via the ``WSGI_APPLICATION`` setting.
8-
9-
Usually you will have the standard Django WSGI application here, but it also
10-
might make sense to replace the whole Django WSGI application with a custom one
11-
that later delegates to the Django one. For example, you could introduce WSGI
12-
middleware here, or combine a Django application with an application of another
13-
framework.
4+
It exposes the WSGI callable as a module-level variable named ``application``.
145
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/
158
"""
169

1710
import os
11+
1812
from django.core.wsgi import get_wsgi_application
1913

20-
# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
21-
# if running multiple sites in the same mod_wsgi process. To fix this, use
22-
# mod_wsgi daemon mode with each site in its own daemon process, or use
23-
# os.environ["DJANGO_SETTINGS_MODULE"] = ".settings"
2414
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
2515

26-
# This application object is used by any WSGI server configured to use this
27-
# file. This includes Django's development server, if the WSGI_APPLICATION
28-
# setting points here.
2916
application = get_wsgi_application()
30-
31-
# Apply WSGI middleware here.
32-
# from helloworld.wsgi import HelloWorldApplication
33-
# application = HelloWorldApplication(application)

manage.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
#!/usr/bin/env python
2+
"""Django's command-line utility for administrative tasks."""
3+
24
import os
35
import sys
46

5-
if __name__ == "__main__":
7+
8+
def main():
9+
"""Run administrative tasks."""
610
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
11+
try:
12+
from django.core.management import execute_from_command_line
13+
except ImportError as exc:
14+
raise ImportError(
15+
"Couldn't import Django. Are you sure it's installed and "
16+
"available on your PYTHONPATH environment variable? Did you "
17+
"forget to activate a virtual environment?"
18+
) from exc
19+
execute_from_command_line(sys.argv)
720

8-
from django.core.management import execute_from_command_line
921

10-
execute_from_command_line(sys.argv)
22+
if __name__ == "__main__":
23+
main()

requirements.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
Django==4.2.27
2-
Unipath==1.1
1+
Django==5.2.10
32
coverage==7.13.1
43
django-cors-headers==4.9.0
54
django-redis==6.0.0
65
django-cachalot==2.8.0
76
djangorestframework==3.16.1
87
gunicorn==23.0.0
98
psycopg[binary]==3.3.2
10-
python-dateutil==2.9.0
11-
python-mimeparse==2.0.0
129
drf-spectacular==0.29.0
1310
legacy-cgi; python_version >= '3.13'

0 commit comments

Comments
 (0)