From the frontend to Django: what we add and preparing the tools
Lesson 1 of 9 · Python web: Django project
The frontend of the Logo creator works in the browser, but it remembers nothing: after the browser is closed the logos disappear, and users have no accounts. For that we need a backend – a program on a server with a database. In this part we build it in Python with the Django framework. First: exactly what we add and how to prepare the computer.
yes – the same HTML, CSS and JavaScript, now as Django templates
user accounts
no
registration, signing in, signing out
saving logos
no (only downloading a file)
logos are saved in the database and can be seen from any device
administration
no
an admin panel: an overview of users and logos
protection
–
everyone sees and deletes only their own logos
The workflow: on the home page the user types a name → generator → sign in or register → the logo is saved → the "My logos" page.
Why Django
Flask
Django
size
small – you add everything yourself
big – "batteries included"
database and models
an extra library
built in (ORM, migrations)
accounts and signing in
an extra library
built in
admin panel
none
built in
for learning
excellent for the first steps
excellent for a whole project
If you have not worked with any Python web framework yet, first go through the short lessons An introduction to Flask and An introduction to Django from the Python area – here we use them on a real project. The terms request, response, route and status code are explained in the lesson The HTTP protocol.
Tools
Tool
For
Check in the command line
Python 3.12 or newer
the language
py --version
pip
installing packages (comes with Python)
py -m pip --version
VS Code + the Python extension
the editor
–
Git
the history of changes and putting the site online (lesson 9)
git --version
On Windows, Python is downloaded from python.org; during installation tick Add python.exe to PATH. The PostgreSQL database is not needed for development – Django uses the built-in SQLite, and we only get PostgreSQL on the server.
A virtual environment and installing Django
Every project has its own virtual environment (.venv) – a separate folder with the packages of that project only, so that versions do not get mixed between projects.
:: Windows, cmd – in the folder where you keep your projects
mkdir logo_kreator_django
cd logo_kreator_django
py -m venv .venv
.venv\Scripts\activate
:: from now on the line starts with (.venv)
python -m pip install --upgrade pip
pip install "django>=5.2,<7"
python -m django --version
On Linux and macOS activation is source .venv/bin/activate. Every time you open a new command-line window, activate the environment again. In VS Code: Ctrl+Shift+P → Python: Select Interpreter → choose the one from .venv.
Version: the examples are written for Django 5.2 (the long-term support version, LTS) and also work in Django 6. On the internet there are many examples for old versions (for example from django.conf.urls import url) – they do not work in new versions.
Video: installing the tools
Video in Serbian with English subtitles – turn on subtitles (CC) in the YouTube player.
A note about the video: the video was recorded for the first version of the project (an older version of Django, Heroku). The ideas are the same, but the code in this lesson differs in details – where they differ, the code on this page is the one that applies.
Practice tasks
For every task there is an example, instructions and a solution.
TASK 01Difficulty: easy
Check the environment
Make a project folder and a virtual environment, install Django and write down the output of the commands python --version, pip list and python -m django --version. Then deactivate the environment (deactivate) and run python -m django --version again. What happened and why?
Instructions
Django is installed only in .venv. Outside the environment Python does not see it (unless it is also installed globally).
Solution
(.venv) > python --version
Python 3.13.1
(.venv) > pip list
Package Version
-------- -------
asgiref 3.8.1
Django 5.2.8
pip 25.3
sqlparse 0.5.3
(.venv) > python -m django --version
5.2.8
(.venv) > deactivate
> python -m django --version
...No module named django
Explanation: packages installed in a virtual environment exist only while it is active.
(The version numbers on your computer may be different.)
Common mistakes and tips
Forgetting to activate the environment is the most common cause of the error No module named django.
The .venv folder is not copied or sent to GitHub – it is made again from requirements.txt.
Check code from the internet: if it uses url() or django.conf.urls, it was written for Django 3 or older.
Check your knowledge
Open the quiz
Preparing for Django
1. What does Django add to the Logo creator compared with the frontend?
2. What is a virtual environment for?
3. Which database does Django use for development without any setup?
Podešavanja kolačića
Koristimo kolačiće da bismo vam pružili najbolje moguće iskustvo. Takođe nam omogućavaju da analiziramo ponašanje korisnika kako bismo stalno poboljšavali veb lokaciju za vas.