- Create a virtual environment
/python -m venv <venv_name>
- Activating virtual environment
/<venvname>/Scripts/activate
- Create a project
/django-admin.py startproject <project_name>
- Create a database
/python manage.py migrate
- Run the server
/python manage.py migrate
- Creating App / Python manage.py <app_name>
- Adding superuser
/python manage.py createsuperuer
- Definition model:
Open a folder <app_name> models.py file, create a model (i.e., the definition of a class) - Activation model:
Open <project_name> /setting.py, the <app_name> added to the INSTALLED_APPS - Register Model
Open <app_name> /admin.py, introduced into the model, and register the model - Migration model
/python manage.py makemigrations
,/python manage.py migrate
due model.py Edit, create church Django how to modify the migration file database, and then apply the migration - Configuration URL:
Open <project_name> /urls.py, introduction <app_name> of views (app automatically generated when creating the document), increasing url mode
two kinds of modes url structure currently understood:
A mode to increase a url:
path('', views.<view_function_name>[, name='<urlpattern_name>'])
''
Representative is requested to the part after the body of the page, for example, the embodiment refers to http: // localhost: 8000, if the''
replace'about/'
said page request http: // localhost:. 8000 / about /
views
is a file <app_name > /views.py,view_function_name
refer to the referenced return web content view function, which will edit the subsequent steps
name='<urlpattern_name>'
(optional) refers to this url model name, so that we can refer to it elsewhere in the code. Whenever the need to provide a link to the home page, we will use this name, URL and not write
two adding a set of url patterns:
path('', include('<other urlpattern>'[, namespace='<namespace_name>']))
If the <app_name> /urls.py create a new extra_urlpatterns in the current file, then the'other urlpattern'
Replace 'extra_urlpatterns', which can be combined so that urlpatterns view url handler
reference: https://docs.djangoproject.com/zh-hans/2.2/topics/http/urls/
namespace='<namespace_name>'
(optional) means able to let the URL learning_logs other projects in the URL area with separate, which is helpful when the project began to expand.
Reference: "Python Programming: from entry to practice" on page 193 - Write view function:
Open the <project_name> /views.py, write the function
currently two ways to understand
a very simple if website content, import HttpResponse, to convert a string of HTML code into the HTML code.
from django.http import HttpResponse
...
return HttpResponse("<h1>Hello World!</h1>")
two complex web content, will be certain. html file as a parameter is added to the render (request, '<html file>') function
return render(request, 'learning_logs/index.html')
- Authoring templates (if used during the preparation of view function is a simple web method, naturally without template):
two ways:
A no inheritance:
the direct line and the code it wants
two inherited from the parent template:
Note the parent and child template formatting template
reference: "Python programming: from entry to practice" & 194 193
Python Web Development Module Django2.2 study notes -1 (Django process of making web pages briefly: (only for windows))
Guess you like
Origin blog.csdn.net/weixin_43243428/article/details/91411646
Recommended
Ranking