Skip to content

Commit ad6b16b

Browse files
makes settings and manage more modern.
1 parent 7b44c4f commit ad6b16b

3 files changed

Lines changed: 20 additions & 19 deletions

File tree

manage.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
#!/usr/bin/env python
2+
"""Django's command-line utility for administrative tasks."""
23
import os
34
import sys
45

5-
if __name__ == "__main__":
6+
7+
def main():
8+
"""Run administrative tasks."""
69
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")
710
try:
811
from django.core.management import execute_from_command_line
9-
except ImportError:
10-
# The above import may fail for some other reason. Ensure that the
11-
# issue is really that Django is missing to avoid masking other
12-
# exceptions on Python 2.
13-
try:
14-
import django
15-
except ImportError:
16-
raise ImportError(
17-
"Couldn't import Django. Are you sure it's installed and "
18-
"available on your PYTHONPATH environment variable? Did you "
19-
"forget to activate a virtual environment?"
20-
)
21-
raise
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
2218
execute_from_command_line(sys.argv)
19+
20+
21+
if __name__ == "__main__":
22+
main()

myproject/settings.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
"""
1212

1313
import os
14+
from pathlib import Path
1415
from typing import List
1516

16-
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
17-
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
17+
# Build paths inside the project like this: BASE_DIR / 'subdir'.
18+
BASE_DIR = Path(__file__).resolve().parent.parent
1819

1920

2021
# Quick-start development settings - unsuitable for production

myproject/urls.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
1. Import the include() function: from django.conf.urls import url, include
1414
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
1515
"""
16-
from django.conf.urls import url
16+
from django.urls import re_path
1717
from django.contrib import admin
1818

1919
from myapp import views
2020

2121
urlpatterns = [
22-
url(r'^$', views.home),
23-
url(r'^admin/', admin.site.urls),
22+
re_path(r'^$', views.home),
23+
re_path(r'^admin/', admin.site.urls),
2424
]

0 commit comments

Comments
 (0)