Skip to content

Commit f805af4

Browse files
authored
Merge branch 'master' into Changes-to-homework-tutorial
2 parents dd4bd4c + 056f91a commit f805af4

Some content is hidden

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

48 files changed

+3139
-2026
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ Current tutorials are:
2020
## Contributing
2121

2222
These tutorials are maintained by [DjangoGirls](http://djangogirls.org/). If you find any mistakes or want to update the tutorial
23-
please [follow the contributing guidelines](https://github.com/DjangoGirls/tutorial-extension/contributing/).
23+
please [follow the contributing guidelines](./contributing/README.md).

book.json

+48-36
Original file line numberDiff line numberDiff line change
@@ -17,42 +17,54 @@
1717
},
1818
"sidebar-ads": {
1919
"ads": [
20-
{
21-
"imageUrl": "https://djangogirls.org/static/img/global/donate/lagos.jpg",
22-
"url": "https://www.patreon.com/djangogirls",
23-
"description": "💖 Support our work and donate to our project! ✨",
24-
"btnText": "Donate now!"
25-
},
26-
{
27-
"imageUrl": "https://posthog.com/static/1cf376d3f6ea36d7fafb9b1c50110603/0b2f4/hosthog-banner.webp",
28-
"url": "https://posthog.com/",
29-
"description": "💖 PostHog offers a suite of product analysis tools! ✨",
30-
"btnText": "Learn more!"
31-
},
32-
{
33-
"imageUrl": "https://static.djangoproject.com/img/logos/django-logo-negative.png",
34-
"url": "https://www.djangoproject.com/",
35-
"description": "💖 The DSF supports the development of Django! ✨",
36-
"btnText": "Learn more!"
37-
},
38-
{
39-
"imageUrl": "https://djangogirls.org/uploads/uploads/lincolnloop.png",
40-
"url": "https://lincolnloop.com/",
41-
"description": "💖 Lincoln Loop provides scalable content platforms! ✨",
42-
"btnText": "Learn more!"
43-
},
44-
{
45-
"imageUrl": "https://djangogirls.org/uploads/uploads/torchbox.png",
46-
"url": "https://torchbox.com/",
47-
"description": "💖 Torchbox, the creators of Wagtail! ✨",
48-
"btnText": "Learn more!"
49-
},
50-
{
51-
"imageUrl": "https://www.pythonanywhere.com/static/anywhere/images/PA-logo.svg",
52-
"url": "https://www.pythonanywhere.com/",
53-
"description": "💖 Host, run, and code Python in the cloud! ✨",
54-
"btnText": "Learn more! "
55-
},
20+
{
21+
"imageUrl": "https://djangogirls.org/static/img/global/donate/lagos.jpg",
22+
"url": "https://surveys.jetbrains.com/s3/w-django-girls-survey-2024",
23+
"description": "💖 Celebrate 10 years with us. Fill our survey! ✨",
24+
"btnText": "Fill in now!"
25+
},
26+
{
27+
"imageUrl": "https://static.djangoproject.com/img/logos/django-logo-negative.png",
28+
"url": "https://www.djangoproject.com/",
29+
"description": "💖 The DSF supports the development of Django! ✨",
30+
"btnText": "Learn more!"
31+
},
32+
{
33+
"imageUrl": "https://djangogirls.org/static/img/global/supporters/DO_Logo_Vertical_Blue.png",
34+
"url": "https://www.digitalocean.com/",
35+
"description": "💖 DigitalOcean simplifies cloud computing! ✨",
36+
"btnText": "Learn more!"
37+
},
38+
{
39+
"imageUrl": "https://djangogirls.org/uploads/uploads/posthog.png",
40+
"url": "https://posthog.com/",
41+
"description": "💖 PostHog offers a suite of product analysis tools! ✨",
42+
"btnText": "Learn more!"
43+
},
44+
{
45+
"imageUrl": "https://djangogirls.org/uploads/uploads/lincolnloop.png",
46+
"url": "https://lincolnloop.com/",
47+
"description": "💖 Lincoln Loop provides scalable content platforms! ✨",
48+
"btnText": "Learn more!"
49+
},
50+
{
51+
"imageUrl": "https://djangogirls.org/uploads/uploads/torchbox.png",
52+
"url": "https://torchbox.com/",
53+
"description": "💖 Torchbox, the creators of Wagtail! ✨",
54+
"btnText": "Learn more!"
55+
},
56+
{
57+
"imageUrl": "https://www.pythonanywhere.com/static/anywhere/images/PA-logo.svg",
58+
"url": "https://www.pythonanywhere.com/",
59+
"description": "💖 Host, run, and code Python in the cloud! ✨",
60+
"btnText": "Learn more! "
61+
},
62+
{
63+
"imageUrl": "https://djangogirls.org/static/img/global/donate/lagos.jpg",
64+
"url": "https://www.patreon.com/djangogirls",
65+
"description": "💖 Support our work and donate to our project! ✨",
66+
"btnText": "Donate now!"
67+
},
5668
{
5769
"imageUrl": "https://djangogirls.org/static/img/global/donate/tshirt.jpg",
5870
"url": "https://djangogirls.org/en/contact/",

en/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Current tutorials are:
1212
* [Homework: add more to your website!](homework/README.md)
1313
* [Homework: secure your website](authentication_authorization/README.md)
1414
* [Homework: create comment model](homework_create_more_models/README.md)
15+
* [Homework: Add Wagtail to your website](add_wagtail_to_your_website/README.md)
1516
* [Optional: PostgreSQL installation](optional_postgresql_installation/README.md)
1617

1718
## Contributing

en/SUMMARY.md

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
* [Homework: add more to your website!](homework/README.md)
55
* [Homework: secure your website](authentication_authorization/README.md)
66
* [Homework: create comment model](homework_create_more_models/README.md)
7+
* [Homework: Add Wagtail to your website](add_wagtail_to_your_website/README.md)
8+
* [Wagtail Installation](add_wagtail_to_your_website/install_wagtail/README.md)
9+
* [Wagtail - Adding the Homepage](add_wagtail_to_your_website/wagtail_integration_adding_homepage/README.md)
10+
* [Wagtail - Adding Posts](add_wagtail_to_your_website/wagtail_integration_adding_posts/README.md)
11+
* [Wagtail - Change Website Homepage](add_wagtail_to_your_website/change_website_homepage/README.md)
712
* [Optional: PostgreSQL installation](optional_postgresql_installation/README.md)
813
* [Optional: Domain](domain/README.md)
914

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Homework: Add Wagtail to your website
2+
3+
> Part of this chapter is based on Wagtail’s official [Getting Started tutorial](https://docs.wagtail.org/en/stable/getting_started/tutorial.html).
4+
5+
We can make our blog even more professional by adding Wagtail to our website while at the same time we are
6+
developing our coding skills in Python and Django. Wagtail is an open source content management system built on
7+
Django, with a strong community and commercial support. It's focused on user experience,
8+
and offers precise control for designers and developers.
9+
10+
The website we built through following the tutorial is a simplified content management system because it allows us
11+
to add and manage content as well as serve it to the visitors of our blog. Wagtail on the other hand is a more complex
12+
content management system with more advanced features. Adding Wagtail to our website will enable us to learn more about
13+
Django and see what cool applications we can build with it.
14+
15+
In this part of the tutorial, we will cover the following aspects:
16+
- [Installing Wagtail and Configuring Wagtail](install_wagtail/README.md)
17+
- [Adding the Homepage](wagtail_integration_adding_homepage/README.md)
18+
- [Adding Posts](wagtail_integration_adding_posts/README.md)
19+
- [Change Website Homepage](change_website_homepage/README.md)
20+
21+
So let's get started!
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# Change Website Homepage to Wagtail Blog Homepage
2+
3+
The Wagtail admin has a nicer and a more user-friendly interface compared to the default Django admin user interface.
4+
For this reason, we would rather use our Wagtail blog as our main blog and ignore the blog we created in the main
5+
tutorial.
6+
7+
We will not remove our initial blog, we will leave it as it is as we may need to use it for more learning. We will
8+
however change the root of our project to point to our Wagtail blog. Make the following changes to your
9+
`mysite/urls.py` as shown below:
10+
11+
First change the `URL` for your first blog to the following:
12+
13+
```python
14+
path('blog/', include('blog.urls')),
15+
```
16+
17+
Next change the `URL` for the Wagtail blog to the following:
18+
19+
```python
20+
path('', include(wagtail_urls)),
21+
```
22+
23+
Your `mysite/urls.py` should now look like below:
24+
25+
{% filename %} mysite/urls.py {% endfilename %}
26+
```python
27+
from django.conf import settings
28+
from django.conf.urls.static import static
29+
from django.contrib import admin
30+
from django.urls import include, path
31+
32+
from wagtail.admin import urls as wagtailadmin_urls
33+
from wagtail import urls as wagtail_urls
34+
35+
urlpatterns = [
36+
path('admin/', admin.site.urls),
37+
path('blog/', include('blog.urls')),
38+
path('cms/', include(wagtailadmin_urls)),
39+
path('', include(wagtail_urls)),
40+
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
41+
42+
```
43+
44+
This will make your Wagtail accessible by visiting `http://127.0.0.1:8000` as shown below
45+
46+
![New Website Homepage](images/wagtail_as_root.png)
47+
48+
and your first blog will now be at `http://127.0.0.1:8000/blog/` as shown below.
49+
50+
![Old Blog's New URL](images/old_blog_url.png)
51+
52+
# Committing our changes to GitHub
53+
54+
Now that we have managed to get Wagtail working well with out blog, we can deploy our changes to our live website
55+
which we deployed to PythonAnywhere earlier on during the main tutorial. To do this, we need to first push our code to
56+
GitHub as we have done before by typing the following in our command line:
57+
58+
```
59+
(myvenv) ~/djangogirls$ git status
60+
```
61+
62+
This will list all the files we have changed. Once we have confirmed those are the changes we have made, we can go
63+
ahead and add the files to be committed by typing the following command:
64+
65+
```
66+
(myvenv) ~/djangogirls$ git add .
67+
```
68+
69+
Next we need to add a commit message for our changes to be saved by typing the following command:
70+
71+
```
72+
(myvenv) ~/djangogirls$ git commit -m "Add Wagtail to our blog"
73+
```
74+
75+
Lastly, we need to push the commit to GitHub by typing the following command:
76+
77+
```
78+
(myvenv) ~/djangogirls$ git push origin HEAD
79+
```
80+
81+
This will push our new changes to GitHub and we are now ready to deploy these changes to PythonAnywhere!
82+
83+
# Deploying the changes to PythonAnywhere
84+
To deploy our changes to [PythonAnywhere](https://pythonanywhere.com) and click `Consoles` and click on
85+
`Bash Console in virtualenv` to open a new Bash console with an activated virtual environment and then type in the
86+
following command:
87+
88+
```
89+
$ git pull origin HEAD
90+
```
91+
92+
This command will pull your changes from GitHub to your PythonAnywhere project.
93+
94+
Next, you need to update the requirements for your project by installing Wagtail and its dependencies. Since we
95+
updated our requirements file, you only need to type in the following command to install the required packages:
96+
97+
```
98+
$ pip install -r requirements.txt
99+
```
100+
101+
Next step is to run migrations for the new models and create the necessary tables in the database. To do this, type the
102+
following command:
103+
104+
```
105+
$ python manage.py migrate
106+
```
107+
108+
Next, you need to run the `collectstatic` command to copy the static files required by Wagtail to the `static` root
109+
folder specified in our `settings.py` file.
110+
111+
```
112+
$ python manage.py collectstatic
113+
```
114+
115+
Lastly, go to `Web` tab and reload your webapp by clicking the `Reload <your-username>.pythonanywhere.com` button and
116+
open `https://<your-username.pythonanywhere.com` in another tab to see your blog now using Wagtail CMS.
117+
118+
You should get the `Welcome to your new Wagtail site!` on your homepage to show that Wagtail is now working as your
119+
website root.
120+
121+
To change the root page of your Wagtail blog visit `https://<your-username.pythonanywhere.com/cms/` and login.
122+
123+
Then follow the steps in [Changing the Wagtail Homepage](../wagtail_integration_adding_homepage/README.md#changing-homepage) section of this tutorial to create a new homepage and change it to be the root of the blog.
124+
125+
To create new posts, follow instructions in the [Adding posts](../wagtail_integration_adding_posts/README.md#adding-blog-posts) section of this tutorial.
126+
127+
After adding your posts, you should see that only posts/pages that have been published are the ones displayed on your blog.
128+
In other words, Wagtail only shows posts which are `live` and a post is only `live` after you click the `Publish` button.
129+
The `Save draft` button merely saves the post without publishing it or making it live.
130+
131+
Also, take note that `live` posts are displayed in the order in which they are published, that is, they are ordered by date.
132+
In Django, the statement to get blog posts would look like `BlogPage.objects.filter(published=True).order_by(published_date)`.
133+
134+
That's all for this tutorial. If you want to learn more about Wagtail, you can read the
135+
[Wagtail documentation](https://guide.wagtail.org/en-latest/) or search for more tutorials on Wagtail online.
136+
137+
Happy coding!
Loading
Loading

0 commit comments

Comments
 (0)