-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #578 from diegorusso/python-django
Create Django learning path
- Loading branch information
Showing
9 changed files
with
611 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
content/learning-paths/servers-and-cloud-computing/django/_index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--- | ||
title: Learn how to deploy a Django application | ||
|
||
minutes_to_complete: 30 | ||
|
||
who_is_this_for: This is an introductory topic for engineers who want to deploy a Django based application on Arm machines. | ||
|
||
learning_objectives: | ||
- Create a simple Django application | ||
- Deploy the Django application using Nginx and PostgreSQL | ||
- Verify that the Django application is working correctly | ||
|
||
prerequisites: | ||
- At least either an [Arm based instance](../csp/) from a cloud service provider, on-premises Arm server, or a Linux virtual machine on your Arm device. | ||
- sudo access to install dependencies and to modify system configuration files. | ||
- Be comfortable with SSH/Linux terminal and basic system administration tasks. | ||
- To install both [Nginx](../nginx/) and [PostgreSQL](../postgresql/) | ||
|
||
author_primary: Diego Russo | ||
|
||
### Tags | ||
skilllevels: Introductory | ||
subjects: Web | ||
armips: | ||
- Neoverse | ||
tools_software_languages: | ||
- Django | ||
- Python | ||
- Nginx | ||
- PostgreSQL | ||
operatingsystems: | ||
- Linux | ||
|
||
|
||
### FIXED, DO NOT MODIFY | ||
# ================================================================================ | ||
weight: 1 # _index.md always has weight of 1 to order correctly | ||
layout: "learningpathall" # All files under learning paths have this same wrapper | ||
learning_path_main_page: "yes" # This should be surfaced when looking for related content. Only set for _index.md of learning path content. | ||
--- |
27 changes: 27 additions & 0 deletions
27
content/learning-paths/servers-and-cloud-computing/django/_next-steps.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
next_step_guidance: Thank you for learning how to deploy a Django application on Arm machines. | ||
|
||
recommended_path: /learning-paths/servers-and-cloud-computing/memcached_cache/ | ||
|
||
further_reading: | ||
- resource: | ||
title: PostgreSQL Documentation | ||
link: https://www.postgresql.org/docs/ | ||
type: documentation | ||
- resource: | ||
title: Nginx Documentation | ||
link: https://nginx.org/en/docs/ | ||
type: documentation | ||
- resource: | ||
title: Django Documentation | ||
link: https://docs.djangoproject.com/ | ||
type: documentation | ||
|
||
|
||
# ================================================================================ | ||
# FIXED, DO NOT MODIFY | ||
# ================================================================================ | ||
weight: 21 # set to always be larger than the content in this path, and one more than 'review' | ||
title: "Next Steps" # Always the same | ||
layout: "learningpathall" # All files under learning paths have this same wrapper | ||
--- |
30 changes: 30 additions & 0 deletions
30
content/learning-paths/servers-and-cloud-computing/django/_review.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
review: | ||
- questions: | ||
question: > | ||
Does Django run on Arm servers? | ||
answers: | ||
- "Yes" | ||
- "No" | ||
correct_answer: 1 | ||
explanation: > | ||
Django is a pure Python application so it is fully supported on 64-bit Arm servers running Linux. | ||
- questions: | ||
question: > | ||
Do you need to perform Arm specific steps during the learning path? | ||
answers: | ||
- "Yes" | ||
- "No" | ||
correct_answer: 2 | ||
explanation: > | ||
The learning path doesn't contains steps specific for Arm as all the software stack used is fully supporte on 64-bit Arm servers running Linux. | ||
# ================================================================================ | ||
# FIXED, DO NOT MODIFY | ||
# ================================================================================ | ||
title: "Review" # Always the same title | ||
weight: 20 # Set to always be larger than the content in this path | ||
layout: "learningpathall" # All files under learning paths have this same wrapper | ||
--- |
152 changes: 152 additions & 0 deletions
152
.../learning-paths/servers-and-cloud-computing/django/create_django_application.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
--- | ||
title: Create the Django application | ||
weight: 3 | ||
|
||
### FIXED, DO NOT MODIFY | ||
layout: learningpathall | ||
--- | ||
|
||
## Create the Django project | ||
|
||
From the terminal where the virtual environment is activated, you need to | ||
create a Django project | ||
|
||
```bash | ||
django-admin startproject myproject | ||
``` | ||
|
||
The above command creates a directory called `myproject` that contains the basic | ||
structure of a Django application. Inspect the project files: | ||
|
||
```bash | ||
tree myproject/ | ||
``` | ||
The output should look like: | ||
|
||
```output | ||
myproject/ | ||
manage.py | ||
myproject | ||
asgi.py | ||
__init__.py | ||
settings.py | ||
urls.py | ||
wsgi.py | ||
``` | ||
|
||
Feel free to explore the content of these files. | ||
|
||
Now you can test the application by starting the development server. | ||
|
||
```bash | ||
cd myproject | ||
python manage.py runserver 0.0.0.0:8000 | ||
``` | ||
You will see messages similar to: | ||
|
||
```output | ||
Watching for file changes with StatReloader | ||
Performing system checks... | ||
System check identified no issues (0 silenced). | ||
You have 18 unapplied migration(s). Your project may not work properly until | ||
you apply the migrations for app(s): admin, auth, contenttypes, sessions. | ||
Run 'python manage.py migrate' to apply them. | ||
November 06, 2023 - 22:34:05 | ||
Django version 4.2.7, using settings 'myproject.settings' | ||
Starting development server at http://0.0.0.0:8000/ | ||
Quit the server with CONTROL-C. | ||
``` | ||
|
||
{{% notice Note %}} | ||
In the above command you speficied 0.0.0.0:8000. This means | ||
that the web server is listening to all available ports. You need to specify | ||
this value if you developing on a remote machine because by default the | ||
development server listens only on localhost | ||
{{% /notice %}} | ||
|
||
Now open a web browser and point it to the IP address of your machine followed | ||
by `:8000`. You should see something like that: | ||
|
||
![alt-text #center](django-install.png "Successful installation of a Django project") | ||
|
||
## Create the Django application | ||
Now that you have a Django project, it's now time to create a Django | ||
application within the project. Type: | ||
|
||
```bash | ||
python manage.py startapp aarch64app | ||
tree aarch64app | ||
``` | ||
|
||
The output should look similar to: | ||
|
||
```output | ||
aarch64app/ | ||
admin.py | ||
apps.py | ||
__init__.py | ||
migrations | ||
__init__.py | ||
models.py | ||
tests.py | ||
views.py | ||
``` | ||
|
||
Again, feel free to explore the content of these files. | ||
|
||
It's now time to write some code that will be executed by the Django | ||
application. | ||
With your favourite editor, open `aarch64app/views.py` and replace the content | ||
with the following: | ||
|
||
```python | ||
import platform | ||
|
||
from django.http import HttpResponse | ||
|
||
# Create your views here. | ||
def index(request): | ||
return HttpResponse(f"Hello world from an {platform.machine()} machine.") | ||
``` | ||
|
||
Next you need to map a URL to this view. Create a new file `aarch64app/urls.py` | ||
with the following content: | ||
|
||
```python | ||
from django.urls import path | ||
|
||
from . import views | ||
|
||
urlpatterns = [ | ||
path("", views.index, name="index"), | ||
] | ||
``` | ||
|
||
Now you need to make it visible at the project level. Edit `myproject/urls.py` | ||
and add the following code | ||
|
||
```python | ||
from django.contrib import admin | ||
from django.urls import include, path | ||
|
||
urlpatterns = [ | ||
path("aarch64app/", include("aarch64app.urls")), | ||
path('admin/', admin.site.urls), | ||
] | ||
``` | ||
|
||
You have now connected the index view with the URL `/aarch64app`. Run the | ||
development web server again with: | ||
|
||
```bash | ||
python manage.py runserver 0.0.0.0:8000 | ||
``` | ||
|
||
Open http://your_IP:8000/aarch64app/ with | ||
your browser. You should see the hello world message. | ||
|
||
|
||
![alt-text #center](django-app.png "Successful call to a Django view") |
Oops, something went wrong.