To learn about the Django structure we first need to initialize a project
For that we need to write the command below in a terminal
django-admin startproject config
Of course this is assuming that the name of your django project is called config, it should look like this
Files in the project directory
- In the config directory we see the following files:
- asgi.py: This is the file responsible for asynchronous server gateway interface
- settings.py: This is the file where we will configure the settings that apply to our entire django project
- urls.py: Here we configure the urls in our django project
- wsgi.py: This file is responsible for rendering pages in the web
- init.py: This file tells python that the files in this folder are a python package and that they can be imported in other files too
Applications in the django project
For this particular config project, I have created 2 apps in it.
users
posts
Notice the naming convection of the apps, they are in plural so that their respective models will be in singular that is: User and Post respectively.
So to create the apps we simply run the following commands
cd config
manage.py startapp users
manage.py startapp posts
Once you run the following you should get something that looks like this
- In each of the following apps we have these files and a folder
- views.py: This file has views which receive a web request and returns a web response
- admin.py: This is the default layout of the admin page which ius already pre-built in django
- init.py: This file marks this particular file as a python package
- apps.py: This file allows you to define metadata specific to this app
- models.py: This is the file that contains your database layout
- tests.py: This file contains tests for debugging the app
- migrations folder:
Templates
After creating our apps we have to create template folders in each of them.
In the templates, respectively there should be another folder with the same name as the app and within this folder is where we can place the html files
Top comments (0)