1. Create a folder, and then create a new terminal window located in the folder
and enter:
django-admin startproject xxx(项目名字)
New files in the folder:
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.
3. After creating the app, you need to register it in django.
Find settings.py, and add a line in installed_apps.
The added content is from the apps.py of the app:
you can see that there is a class called AppyanbanConfig,
so in settings.py Add in install_apps:
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.
5. Then write the index function in views, which is the simplest, that is, it will return a hello after using the index path:
6. Then create a new terminal window located in the folder above the manage.py folder, and enter:
python manage.py runserver
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:
it is the hello just now.
Then the django project is created.