Django Overview

Ukeme Wilson
4 min readJun 25, 2024

--

What is Django?
Django is a python web framework used in the creation of complex database driven websites. It makes it easy to create secure and maintainable websites using python. (Other python web frameworks are Flask and FastApi).

Web framework is a software framework designed to aid the development of web applications using web services, web resources and web APIs.

Django is versatile and follows the “Batteries included” principle where almost everything you need can be gotten from Django and you don’t have to build from scratch. It is able to deliver content in almost any format (HTML, RSS, JSON, XML).

Getting started:

Django can be installed using a simple command on your terminal. It is expected that you have python and pip already installed on your pc.

Set up venv:


$ python -m venv venv

or

$ python3 -m venv venv

This creates a virtual environment with a name called venv. (You should see a folder/directory created called “venv”).

The next step is to activate the virtual environment.

# windows
$ venv\Scripts\activate
# linux, macOs
$ source venv/bin/activate

Once activated, you can then install django.

$ pip install Django

# Or

$ pip3 install django

If this runs well, you can verify by running and see something like this 5.0.6 (You may not have the exact number).

$ python -m django - version

Project and Apps

Project

A Project in Django is a collection of configurations, applications and settings that work together to accomplish your goal/task of create a web application. For example, you wish to create a website for books (can be any name though), that becomes your project. Since Django doesn’t want you to write everything about the “books” project, it sets up a directory for you containing some configurations and settings.

$ django-admin startproject project_name

You should see a folder/directory with this structure.

wsgi.py: This serves as the entry point for WSGI (WEB SERVER GATEWAY INTERFACE) compatible web server. It defines how web servers communicate with web applications allow them to handle http requests and responses. It serves as a bridge between web servers (NGINX, APACHE) and web applications in python.

urls.py: This serves to route incoming request by creating a URL pattern mapping to view functions/classes. For example, when you go to a site https://xyz.com/ or https://xyz.com/name, the “/” or the “/name” are routes that are specified to carry out a particular task described in the view function.

settings.py: This contains settings and configurations (databases, installed apps, middleware) needed for the project to run properly.

__init__.py: This is an empty file that tells python to treat the folder as a python package.

manage.py: This is a command line utility that lets you interact with the Django project such as creating Django apps, running the server and doing migrations.

Apps

Apps (applications) are python packages that serves a specific function inside the project. A project would usually consist of multiple Apps. For example, a typical book could consist of numerous chapters, table of content, index page etc. This allows you to organize your project into separate reusable units.

$ cd project_name
$ python manage.py startapp app_name

You should now see a folder/directory with this structure.

migrations/: Directory containing database migration files generated by Django when changes are made to models.

__init__.py: Python package indicator file.

admin.py: Configuration for registering models with the Django admin interface.

apps.py: Configuration for the app itself, including metadata and configuration settings.

models.py: Defines data models using Django’s ORM (Object-Relational Mapping) for interacting with the database such as to add, modify, delete and query records.

tests.py: Contains unit tests for the app.

views.py: Contains view functions or classes that handle HTTP requests and generate HTTP responses.

Running the Server

Now you can run the server by running.

python manage.py runserver

You should see “development server at http://127.0.0.1:8000/”.
Click on the link and this should display.

If you are able to get here, congrats. You have created your first Django project.

Conclusion

There are still a lot to learn and still a lot to do on your project, but this is a big step in the right direction for you.

Stick around as I uncover other areas you need to learn to make your project much better.

Let’s Get in Touch! Follow me on:

>GitHub: @bosukeme

>Linkedin: Ukeme Wilson

You can read other of my Medium Articles here

--

--