上QQ阅读APP看书,第一时间看更新
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.