官术网_书友最值得收藏!

Creating an application

Now, let's create our first Django application. We will create a blog application from scratch. From the project's root directory, run the following command:

python manage.py startapp blog

This will create the basic structure of the application, which looks like this:

blog/
__init__.py
admin.py
apps.py
migrations/
__init__.py
models.py
tests.py
views.py

These files are as follows:

  • admin.py: This is where you register models to include them in the Django administration site—using the Django admin site is optional.
  • apps.py: This includes the main configuration of the blog application.
  • migrations: This directory will contain database migrations of your application. Migrations allow Django to track your model changes and synchronize the database accordingly.
  • models.py: Data models of your application—all Django applications need to have a models.py file, but this file can be left empty.
  • tests.py: This is where you can add tests for your application.
  • views.py: The logic of your application goes here; each view receives an HTTP request, processes it, and returns a response.
主站蜘蛛池模板: 大洼县| 白山市| 盱眙县| 达孜县| 南郑县| 宣威市| 毕节市| 和静县| 汉源县| 思茅市| 永安市| 葫芦岛市| 深州市| 夏河县| 田东县| 宝清县| 隆德县| 溆浦县| 大城县| 兴国县| 天祝| 桃源县| 九台市| 汝阳县| 乾安县| 邮箱| 海伦市| 南岸区| 那曲县| 东辽县| 周宁县| 景泰县| 梅河口市| 恩平市| 连平县| 澄城县| 宝坻区| 二连浩特市| 北碚区| 渝北区| 苏尼特右旗|