DEV Community

Marvin Ochieng
Marvin Ochieng

Posted on

Day4 of how I created two applications with a page in a Django project

Creating a programming environment
After selecting a folder in my text editor (VS Code), I opened the terminal to run

python -m venv env 
Enter fullscreen mode Exit fullscreen mode

to create an environment called env.

.env/Scripts/activate 
Enter fullscreen mode Exit fullscreen mode

or

Source env/Scripts/activate 
Enter fullscreen mode Exit fullscreen mode

are commands used to activate the programming environment

Installing Django
I used

pip install django 
Enter fullscreen mode Exit fullscreen mode

in the newly created environment to install Django

Project Directory
To start my project directory, I run:

django-admin startproject myproject 
Enter fullscreen mode Exit fullscreen mode

in the vs code terminal to generate root directory with project name, which in this case is called myproject

Image description
this project is blue in color as shown in the figure above

Project Setting Directory
Inside the root directory, there is another directory called myproject, just as the project name.
This other directory contains the project-wide settings and configurations as shown in the figure below:

Image description

init.py: A file that tells Python that all files in the directory should be considered a Python package. Without this file, we cannot import files from another directory which we will be doing a lot of in Django!

settings.py: Contains all the project’s settings and configurations.

urls.py: The URL declarations for the project are a “table of contents” of your Django-powered site.

asgi.py: allows for an optional Asynchronous Server Gateway Interface(ASGI) to be run

wsgi.py: An entry point for Web Server Gateway Interface(WSGI) compatible web servers to serve your project. It helps Django serve our eventual web pages

Applications
Django projects are composed of one or more apps. Each app is a Python package that follows a certain convention. In this case I created two apps called app1 and app2 respectively
This is how I created the applications inside an already initiated Django project

manage.py startapp app1 
Enter fullscreen mode Exit fullscreen mode

for app1 and the picture bellow shows how it looks a text editor, which in this case is VS Code

Image description

manage.py startapp app2 
Enter fullscreen mode Exit fullscreen mode

for app2 and the picture below shows how it looks like in VS Code

Image description
admin.py: Configuration for the Django admin interface.

apps.py: Configuration for the app itself.

models.py: Contains the database models for the app.

tests.py: Contains tests for the app.

views.py: Contains the request/response logic for the app.

migrations/: Contains database migrations for the app.

Templates
Templates(what users see, HTML and CSS) are typically stored in a templates directory within each app or in a project-wide templates directory.
The selected file that is blue in color is the template for the first app
Image description

The selected file that is blue in color is the template for the second app

Image description

This stracture helps organize Django Project making it easier to maintain, especially for begginers.

Top comments (0)