Skip to content

Commit f2c6ec3

Browse files
authored
Merge pull request #1757 from adamantike/django-3.2
Upgrade tutorial to Django 3.2
2 parents fd6d6ed + 3702754 commit f2c6ec3

File tree

14 files changed

+57
-24
lines changed

14 files changed

+57
-24
lines changed

book.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"py_min_version": "3.6",
77
"py_min_release": "3.6.8",
88
"pa_py_version": "3.8",
9-
"django_version": "2.2.4"
9+
"django_version": "3.2.10"
1010
},
1111
"links": {
1212
"sidebar": {

en/deploy/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ You can also go to the "Files" page and navigate around using PythonAnywhere's b
245245
Your site should now be live on the public Internet! Click through to the PythonAnywhere "Web" page to get a link to it. You can share this with anyone you want. :)
246246

247247

248-
> **Note** This is a beginners' tutorial, and in deploying this site we've taken a few shortcuts which aren't ideal from a security point of view. If and when you decide to build on this project, or start a new project, you should review the [Django deployment checklist](https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/) for some tips on securing your site.
248+
> **Note** This is a beginners' tutorial, and in deploying this site we've taken a few shortcuts which aren't ideal from a security point of view. If and when you decide to build on this project, or start a new project, you should review the [Django deployment checklist](https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/) for some tips on securing your site.
249249
250250

251251
## Debugging tips

en/django_admin/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ Make sure that at least two or three posts (but not all) have the publish date s
5252

5353
![Django admin](images/edit_post3.png)
5454

55-
If you want to know more about Django admin, you should check Django's documentation: https://docs.djangoproject.com/en/2.2/ref/contrib/admin/
55+
If you want to know more about Django admin, you should check Django's documentation: https://docs.djangoproject.com/en/3.2/ref/contrib/admin/
5656

5757
This is probably a good moment to grab a coffee (or tea) or something to eat to re-energize yourself. You created your first Django model – you deserve a little break!

en/django_forms/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ Feel free to change the title or the text and save the changes!
374374

375375
Congratulations! Your application is getting more and more complete!
376376

377-
If you need more information about Django forms, you should read the documentation: https://docs.djangoproject.com/en/2.2/topics/forms/
377+
If you need more information about Django forms, you should read the documentation: https://docs.djangoproject.com/en/3.2/topics/forms/
378378

379379
## Security
380380

en/django_installation/instructions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ Now, run `pip install -r requirements.txt` to install Django.
203203
```
204204
(myvenv) ~$ pip install -r requirements.txt
205205
Collecting Django~={{ book.django_version }} (from -r requirements.txt (line 1))
206-
Downloading Django-{{ book.django_version }}-py3-none-any.whl (7.1MB)
206+
Downloading Django-{{ book.django_version }}-py3-none-any.whl (7.9MB)
207207
Installing collected packages: Django
208208
Successfully installed Django-{{ book.django_version }}
209209
```

en/django_models/README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ djangogirls
9292
├── db.sqlite3
9393
├── manage.py
9494
├── mysite
95+
│   ├── asgi.py
9596
│   ├── __init__.py
9697
│   ├── settings.py
9798
│   ├── urls.py
@@ -102,7 +103,7 @@ djangogirls
102103
103104
```
104105

105-
After creating an application, we also need to tell Django that it should use it. We do that in the file `mysite/settings.py` -- open it in your code editor. We need to find `INSTALLED_APPS` and add a line containing `'blog.apps.BlogConfig',` just above `]`. So the final product should look like this:
106+
After creating an application, we also need to tell Django that it should use it. We do that in the file `mysite/settings.py` -- open it in your code editor. We need to find `INSTALLED_APPS` and add a line containing `'blog',` just above `]`. So the final product should look like this:
106107

107108
{% filename %}mysite/settings.py{% endfilename %}
108109
```python
@@ -113,7 +114,7 @@ INSTALLED_APPS = [
113114
'django.contrib.sessions',
114115
'django.contrib.messages',
115116
'django.contrib.staticfiles',
116-
'blog.apps.BlogConfig',
117+
'blog',
117118
]
118119
```
119120

@@ -163,7 +164,7 @@ Now we define the properties we were talking about: `title`, `text`, `created_da
163164
- `models.DateTimeField` – this is a date and time.
164165
- `models.ForeignKey` – this is a link to another model.
165166

166-
We will not explain every bit of code here since it would take too much time. You should take a look at Django's documentation if you want to know more about Model fields and how to define things other than those described above (https://docs.djangoproject.com/en/2.2/ref/models/fields/#field-types).
167+
We will not explain every bit of code here since it would take too much time. You should take a look at Django's documentation if you want to know more about Model fields and how to define things other than those described above (https://docs.djangoproject.com/en/3.2/ref/models/fields/#field-types).
167168

168169
What about `def publish(self):`? This is exactly the `publish` method we were talking about before. `def` means that this is a function/method and `publish` is the name of the method. You can change the name of the method if you want. The naming rule is that we use lowercase and underscores instead of spaces. For example, a method that calculates average price could be called `calculate_average_price`.
169170

@@ -181,8 +182,8 @@ The last step here is to add our new model to our database. First we have to mak
181182
```
182183
(myvenv) ~/djangogirls$ python manage.py makemigrations blog
183184
Migrations for 'blog':
184-
blog/migrations/0001_initial.py:
185-
- Create model Post
185+
blog/migrations/0001_initial.py
186+
- Create model Post
186187
```
187188

188189
**Note:** Remember to save the files you edit. Otherwise, your computer will execute the previous version which might give you unexpected error messages.

en/django_start_project/README.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ The `(myvenv) C:\Users\Name\djangogirls>` part shown here is just example of the
5353
djangogirls
5454
├── manage.py
5555
├── mysite
56+
│   ├── asgi.py
5657
│   ├── __init__.py
5758
│   ├── settings.py
5859
│   ├── urls.py
@@ -87,7 +88,7 @@ In `settings.py`, find the line that contains `TIME_ZONE` and modify it to choos
8788
TIME_ZONE = 'Europe/Berlin'
8889
```
8990

90-
A language code consist of the language, e.g. `en` for English or `de` for German, and the country code, e.g. `de` for Germany or `ch` for Switzerland. If English is not your native language, you can add this to change the default buttons and notifications from Django to be in your language. So you would have "Cancel" button translated into the language you defined here. [Django comes with a lot of prepared translations](https://docs.djangoproject.com/en/2.2/ref/settings/#language-code).
91+
A language code consist of the language, e.g. `en` for English or `de` for German, and the country code, e.g. `de` for Germany or `ch` for Switzerland. If English is not your native language, you can add this to change the default buttons and notifications from Django to be in your language. So you would have "Cancel" button translated into the language you defined here. [Django comes with a lot of prepared translations](https://docs.djangoproject.com/en/3.2/ref/settings/#language-code).
9192

9293
If you want a different language, change the language code by changing the following line:
9394

@@ -102,7 +103,7 @@ We'll also need to add a path for static files. (We'll find out all about static
102103
{% filename %}mysite/settings.py{% endfilename %}
103104
```python
104105
STATIC_URL = '/static/'
105-
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
106+
STATIC_ROOT = BASE_DIR / 'static'
106107
```
107108

108109
When `DEBUG` is `True` and `ALLOWED_HOSTS` is empty, the host is validated against `['localhost', '127.0.0.1', '[::1]']`. This won't
@@ -118,7 +119,7 @@ ALLOWED_HOSTS = ['127.0.0.1', '.pythonanywhere.com']
118119
119120
> Also add `.amazonaws.com` to the `ALLOWED_HOSTS` if you are using cloud9
120121
121-
> If you are hosting your project on `Glitch.com`, let us protect the Django secret key that needs to
122+
> If you are hosting your project on `Glitch.com`, let us protect the Django secret key that needs to
122123
> remain confidential (otherwise, anyone remixing your project could see it):
123124
>
124125
> * First, we are going to create a random secret key.
@@ -130,8 +131,8 @@ ALLOWED_HOSTS = ['127.0.0.1', '.pythonanywhere.com']
130131
> print(get_random_secret_key())'
131132
> ```
132133
> This should display a long random string, perfect to use as a secret key for your brand new Django web site.
133-
> We will now paste this key into a `.env` file that Glitch will only show you if you are the owner of the web site.
134-
>
134+
> We will now paste this key into a `.env` file that Glitch will only show you if you are the owner of the web site.
135+
>
135136
> * Create a file `.env` at the root of your project and add the following property in it:
136137
>
137138
> {% filename %}.env{% endfilename %}
@@ -143,6 +144,8 @@ ALLOWED_HOSTS = ['127.0.0.1', '.pythonanywhere.com']
143144
>
144145
> {% filename %}mysite/settings.py{% endfilename %}
145146
> ```python
147+
> import os
148+
>
146149
> SECRET_KEY = os.getenv('SECRET')
147150
> ```
148151
> * And a little further down in the same file, we inject the name of your new Glitch website:
@@ -165,7 +168,7 @@ This is already set up in this part of your `mysite/settings.py` file:
165168
DATABASES = {
166169
'default': {
167170
'ENGINE': 'django.db.backends.sqlite3',
168-
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
171+
'NAME': BASE_DIR / 'db.sqlite3',
169172
}
170173
}
171174
```
@@ -176,13 +179,13 @@ To create a database for our blog, let's run the following in the console: `pyth
176179
```
177180
(myvenv) ~/djangogirls$ python manage.py migrate
178181
Operations to perform:
179-
Apply all migrations: auth, admin, contenttypes, sessions
182+
Apply all migrations: admin, auth, contenttypes, sessions
180183
Running migrations:
181-
Rendering model states... DONE
182184
Applying contenttypes.0001_initial... OK
183185
Applying auth.0001_initial... OK
184186
Applying admin.0001_initial... OK
185187
Applying admin.0002_logentry_remove_auto_add... OK
188+
Applying admin.0003_logentry_add_action_flag_choices... OK
186189
Applying contenttypes.0002_remove_content_type_name... OK
187190
Applying auth.0002_alter_permission_name_max_length... OK
188191
Applying auth.0003_alter_user_email_max_length... OK
@@ -192,6 +195,9 @@ Running migrations:
192195
Applying auth.0007_alter_validators_add_error_messages... OK
193196
Applying auth.0008_alter_user_username_max_length... OK
194197
Applying auth.0009_alter_user_last_name_max_length... OK
198+
Applying auth.0010_alter_group_name_max_length... OK
199+
Applying auth.0011_update_proxy_permissions... OK
200+
Applying auth.0012_alter_user_first_name_max_length... OK
195201
Applying sessions.0001_initial... OK
196202
```
197203

en/django_urls/README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,23 @@ The last part, `name='post_list'`, is the name of the URL that will be used to i
9393

9494
If you try to visit http://127.0.0.1:8000/ now, then you'll find some sort of 'web page not available' message. This is because the server (remember typing `runserver`?) is no longer running. Take a look at your server console window to find out why.
9595

96-
![Error](images/error1.png)
96+
{% filename %}{{ warning_icon }} command-line{% endfilename %}
97+
98+
```
99+
return _bootstrap._gcd_import(name[level:], package, level)
100+
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
101+
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
102+
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
103+
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
104+
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
105+
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
106+
File "/Users/ola/djangogirls/blog/urls.py", line 5, in <module>
107+
path('', views.post_list, name='post_list'),
108+
AttributeError: module 'blog.views' has no attribute 'post_list'
109+
```
97110

98111
Your console is showing an error, but don't worry – it's actually pretty useful: It's telling you that there is __no attribute 'post_list'__. That's the name of the *view* that Django is trying to find and use, but we haven't created it yet. At this stage, your `/admin/` will also not work. No worries – we will get there.
99112
If you see a different error message, try restarting your web server. To do that, in the console window that is running the web server, stop it by pressing Ctrl+C (the Control and C keys together). On Windows, you might have to press Ctrl+Break. Then you need to restart the web server by running a `python manage.py runserver` command.
100113

101114

102-
> If you want to know more about Django URLconfs, look at the official documentation: https://docs.djangoproject.com/en/2.2/topics/http/urls/
115+
> If you want to know more about Django URLconfs, look at the official documentation: https://docs.djangoproject.com/en/3.2/topics/http/urls/

en/django_urls/images/error1.png

-51.1 KB
Binary file not shown.

en/django_views/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ Another error! Read what's going on now:
3939

4040
This shows that the server is running again, at least, but it still doesn't look right, does it? Don't worry, it's just an error page, nothing to be scared of! Just like the error messages in the console, these are actually pretty useful. You can read that the *TemplateDoesNotExist*. Let's fix this bug and create a template in the next chapter!
4141

42-
> Learn more about Django views by reading the official documentation: https://docs.djangoproject.com/en/2.2/topics/http/views/
42+
> Learn more about Django views by reading the official documentation: https://docs.djangoproject.com/en/3.2/topics/http/views/

0 commit comments

Comments
 (0)