- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are projects and apps in Django?
Django is a popular web framework used for the development of websites. Django follows the MVT (Model-View-Template) architecture. Here, Model is responsible for the data and logical structure of your project, View contains the business logic and Template is responsible for rendering the HTML files.
The hierarchy of project in Django consists of projects and apps. Project refers to the entire web application. Apps are the functionalities that are part of the web application. All of them work individually and can be reused.
Creation of a project
A project is essentially a collection of settings for a specific instance of Django. It includes database configurations, application, and Django-specific options. In simple terms, a project refers to the entire web application and all its parts. The below command will help you create a project in Django.
django-admin startproject yourprojectname
Creation of an app
An app in Django is a sub module in a project. It is stand-alone and not intertwined with other apps in the project. to create an app in django, you need to have created a project first. Then, you can create an app using the following command.
django-admin startapp yourappname
Django project example
In this section, we will explore an example to understand Django better.
If you were to create an ecommerce website to buy and sell books. Your website has the following functionalities, catalogue, user account, and payment. If you were to implement this project in Django, then your ecommerce website would be the project and all the functionalities would be apps individually.
Creating a project is the first step.
Django-admin startproejct ecommercesite
A folder with the project’s name will be created in your current directory. By using the cd command, you can navigate to the project folder, and you can view the contents of the folder using the dir command.
> C:/user/desktop/project/ecommercesite>cd ecommercesite >C:/user/desktop/project/ecommercesite>dir Mode LastWriteTime Length Name ---- ------------- ------ ---- d----- 4/15/2022 1:54 PM ecommercesite -a---- 4/15/2022 1:54 PM 691 manage.py
The ecommerce site directory has the folder structure of the project
(base) PS C:\Users\jsmur\desktop\tutorialspoint\djangoproject\ecommercesite\ecommercesite> dir Directory: C:\Users\jsmur\desktop\tutorialspoint\djangoproject\ecommercesite\ecommercesite Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 4/15/2022 1:54 PM 419 asgi.py -a---- 4/15/2022 1:54 PM 3365 settings.py -a---- 4/15/2022 1:54 PM 776 urls.py -a---- 4/15/2022 1:54 PM 419 wsgi.py -a---- 4/15/2022 1:54 PM 0 __init__.py
Now, to create an app, you must go back to the project directory and create an app.
(base) PS C:\Users\jsmur\desktop\tutorialspoint\djangoproject\ecommercesite> django-admin startapp catalogue (base) PS C:\Users\jsmur\desktop\tutorialspoint\djangoproject\ecommercesite> dir Directory: C:\Users\jsmur\desktop\tutorialspoint\djangoproject\ecommercesite Mode LastWriteTime Length Name ---- ------------- ------ ---- d----- 4/15/2022 2:07 PM catalogue d----- 4/15/2022 1:54 PM ecommercesite -a---- 4/15/2022 1:54 PM 691 manage.py
The folder structure of the app catalogue can be seen below.
(base) PS C:\Users\jsmur\desktop\tutorialspoint\djangoproject\ecommercesite> cd catalogue (base) PS C:\Users\jsmur\desktop\tutorialspoint\djangoproject\ecommercesite\catalogue> dir Directory: C:\Users\jsmur\desktop\tutorialspoint\djangoproject\ecommercesite\catalogue Mode LastWriteTime Length Name ---- ------------- ------ ---- d----- 4/15/2022 2:07 PM migrations -a---- 4/15/2022 2:07 PM 66 admin.py -a---- 4/15/2022 2:07 PM 156 apps.py -a---- 4/15/2022 2:07 PM 60 models.py -a---- 4/15/2022 2:07 PM 63 tests.py -a---- 4/15/2022 2:07 PM 66 views.py -a---- 4/15/2022 2:07 PM 0 __init__.py
This is how a project with an app can be created in Django.
Kickstart Your Career
Get certified by completing the courseGet Started