This django file structure guide will walk you through the essential elements of a django project.
Contents
- Project Root Directory
- Project Directory (e.g., you_project_name)
- Applications (Apps)
- Templates Directory
- Static Directory
- Media Directory
- Virtual Environment (venv/)
1. Project Root Directory
This directory contains the entire Django project. It contains
- manage.py: It is a command line utility that allows us to interact with project. Mainly use to start development server, create apps, run migrations etc.
- Project Folder (Your Project name folder): It contains setting and configurations of our project.
2. Project Directory (e.g., you_project_name)
This is a folder that has configurations for our Django projects. It include files like:
- init.py:
- settings.py: Contains setting for our projects such as configurations, database settings, installed apps, allowed hosts, middleware.
- urls.py: It contains URL for our projects (Routing requests for our views).
- asgi.py:
- wsgi.py:
3. Applications (Apps):
- models.py: It contains Data Structure for you project or we can say app's data/ structure of the database.
- views.py: Business logic (handling requests and responses)
- urls.py: your app specific url
- forms.py: structure and validation logic for the forms
- admin.py: Django admin panel(Dashboard) by registering the models (by creating a superuser and login to the Django's admin)
- apps.py:
- migrations/: Contains database migrations files.Each time you make any changes to your database you will see a new file with some random naes in this folder (e.g. 0001_initial, 0002_model_you_made_or_changes, ...)
4. Templates Directory:
- base.html:This contains shared code which is common in many files for example headers, footers which you want in your multiple pages.
*- other files that extend from base.html for specific views *: Lets say login.html, home.html etc.
5. Static Directory:It contains static files such as CSS, JavaScript, images. App specific directories or global one (as per your requirements).
6. Media Directory: User uploaded files for example documents, any other files may be a profile picture of a user etc.
7. Virtual Environment (venv/): Make a habit of creating a virtual environment for each of the django project to isolate project dependencies. It is important to note that it is essential for project specific packages without disturbing any global environment.
your_project_name/
│
├── manage.py
├── your_project_name/
│ ├── init.py
│ ├── settings.py
│ ├── urls.py
│ ├── wsgi.py
│ └── asgi.py
│
├── your_app_one/
│ ├── init.py
│ ├── admin.py
│ ├── apps.py
│ ├── models.py
│ ├── views.py
│ ├── urls.py
│ └── migrations/
│
├── your_app_two/
│ ├── init.py
│ ├── admin.py
│ ├── apps.py
│ ├── models.py
│ ├── views.py
│ └── migrations/
│
├── templates/
│ ├── base.html
│ └── home.html
│
└── static/
├── css/
└── js/
Conclusion
Understanding file structure before starting any projects in any language is very crucial and essential for efficient project development. I hope now it becomes easier for you all to navigate and manage your code bases.
Please feel free to comment your thoughts or any tips.
If you want all essential django commands at one place please comment
BONUS
Commands that you should know for manage.py
**1. python manage.py runserver ** : To start the server **2. python manage.py makemigrations** : Creating new migrations on the changes made in your models. **3. python manage.py migrate ** : Applying or unapplying migrations **4. python manage.py createsuperuser**: Access to django admin panel
以上是Django File Structure for Developers的详细内容。更多信息请关注PHP中文网其他相关文章!

Python适合数据科学、Web开发和自动化任务,而C 适用于系统编程、游戏开发和嵌入式系统。 Python以简洁和强大的生态系统着称,C 则以高性能和底层控制能力闻名。

2小时内可以学会Python的基本编程概念和技能。1.学习变量和数据类型,2.掌握控制流(条件语句和循环),3.理解函数的定义和使用,4.通过简单示例和代码片段快速上手Python编程。

Python在web开发、数据科学、机器学习、自动化和脚本编写等领域有广泛应用。1)在web开发中,Django和Flask框架简化了开发过程。2)数据科学和机器学习领域,NumPy、Pandas、Scikit-learn和TensorFlow库提供了强大支持。3)自动化和脚本编写方面,Python适用于自动化测试和系统管理等任务。

两小时内可以学到Python的基础知识。1.学习变量和数据类型,2.掌握控制结构如if语句和循环,3.了解函数的定义和使用。这些将帮助你开始编写简单的Python程序。

如何在10小时内教计算机小白编程基础?如果你只有10个小时来教计算机小白一些编程知识,你会选择教些什么�...

使用FiddlerEverywhere进行中间人读取时如何避免被检测到当你使用FiddlerEverywhere...

Python3.6环境下加载Pickle文件报错:ModuleNotFoundError:Nomodulenamed...

如何解决jieba分词在景区评论分析中的问题?当我们在进行景区评论分析时,往往会使用jieba分词工具来处理文�...


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

禅工作室 13.0.1
功能强大的PHP集成开发环境

WebStorm Mac版
好用的JavaScript开发工具

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

SublimeText3 Linux新版
SublimeText3 Linux最新版

记事本++7.3.1
好用且免费的代码编辑器