File Structure in Django

For creating Django projects you must write the below command:

Command:

django-admin startproject basic

This will create a directory structure like this:

Django File Structure 1

__init__.py: Its plays a key role in organizing code within the package in Django.

asgi.py:  This file is used to configure the project to run on ASGI(Asynchronous Server Gateway Interface) server and support for asynchronous communication like web socket and real-time features.

manage.py: This defines utility for interacting with the project.

urls.py: It manages all the routing of the project.

setting.py: It sets all the configuration which is needed in the project.

wsgi.py: This file is used to configure the project on the WSGI server. It enables the application to manage traditional synchronous web requests.

In the project, we need to create an app after installation of Django.

Create an app with the below command inside the project folder.

Command:

django-admin startapp authentication

authentication is the name of the project app.

This will create the following directory structure which holds in the application(authentication)

Djnago File Structure 2

__init__.py: In django application __init__.py marks the directory as a Python package and it includes initialization code for the application(app).

admin.py: In Django admin.py is used to register the model which is shown in django-admin template.

apps.py: This file defines the configuration for an application in Django.

models.py: This file is used to define the database schema for an application.

views.py: This file contains the application logic which handles the incoming requests, interacts with models and returns responses. 

tests.py: In Django this file is used to automate test cases for an application.

You may also like...