Getting Started with Django
A simple and comprehensive guide to Django, a widely used web framework.
Last updated
A simple and comprehensive guide to Django, a widely used web framework.
Last updated
This page aims to help beginners getting started with Django, a popular web framework written in Python.
Django is a modern web framework that comes with the "batteries-included" concept which means it provides modules and libraries for many common features required in modern web development:
authentication flow (login and register)
database access
powerful command-line interface (CLI)
helpers to manage properly forms, models, and data validation
flexible routing system
built-in security patterns
Besides the common features and modules provided by Django core, this amazing framework is constantly improved by many open-source enthusiasts and also enhanced by other libraries coded to be used and integrated with ease in Django - the official Django links are below:
To start using Django a few tools and libraries are required. Being a Python library, to run properly Django requires Python to be executed without exceptions and fully complete its mission. On top of this, other tools are recommended for a full-featured Django environment:
Python3 - the latest actively supported version of Python
Basic knowledge in working with virtual environments
How to check Python installation
Check GIT instalation
How to create a virtual environment
Virtual environments are useful to execute a Python project in isolation in a shared environment.
Django can be installed in many ways and the most recommended way is to use PIP, the official Python package manager. Here is the complete list with commands
For Windows-based systems, the activation command is different (without calling source
):
Once the Virtual Environment is up and running, we can install Django and start using it.
How to check the installation:
In this case, the installed version is 3.2.3
the latest stable version.
Django help us to generate a project skeleton via a command-line utility command called django-admin. Let's use it and generate our first Django project:
Once our working directory is hellodjango (feel free to use another name), the next step is to call django-admin and generate the project:
Start the project
If all goes well, our newly created Django app should be visible in the browser.
The console will show the current execution status and a few warnings:
Django migrations refer to the database state and tables. The application is provided with usable authentication by default and to make use of this included feature, we need to run the database migration and create all required tables.
The output should be similar to this:
Create a Django superuser
To access the manage all tables, users, and permissions Django comes with the "superuser" concept witch is like an admin or a root user for Unix. Let's create a superuser using the CLI:
The command will ask for username, password, and email address. Once the process is completed, we can use the superuser account to access the Django administration section:
The admin section can be visited at http://localhost:8000/admin
For more Django-related resource, please access:
Django - the official website
A curated list with Django apps and dashboards provided by AppSeed