The detailed process of mac creating a django project

1. Create a folder, and then create a new terminal window located in the folder
and enter:

django-admin startproject xxx(项目名字)

insert image description here
New files in the folder:
insert image description here

2. Then create a new terminal window located in the folder above manage.py (that is, this folder contains manage.py) and
enter:

python manage.py startapp xx(app名称)

Generally, only one app needs to be created for a project.
insert image description here
insert image description here

3. After creating the app, you need to register it in django.
Find settings.py, and add a line in installed_apps.
insert image description here
The added content is from the apps.py of the app:
insert image description here
you can see that there is a class called AppyanbanConfig,
so in settings.py Add in install_apps:
insert image description here
Don't forget the comma.

4. Write the corresponding relationship between url and view function, first import views in urls, and then add a path in it, which means that views can be accessed from this path. The role of views is to receive requests and respond to content.
insert image description here

5. Then write the index function in views, which is the simplest, that is, it will return a hello after using the index path:
insert image description here

6. Then create a new terminal window located in the folder above the manage.py folder, and enter:

python manage.py runserver

insert image description here
Then open it in the browser:
localhost:8000/index
(whatever path you entered in the path just now, just add something after localhost:8000, for example, if it is: path('', views.index), then you can directly enter localhost:8000)
is opened like this:
insert image description here
it is the hello just now.

Then the django project is created.

Guess you like

Origin blog.csdn.net/xxxli_/article/details/123524021