When requesting a page through the browser, the view function is used to process the request, and the content of the page is returned to the browser after the view function is processed.
One, the use of view functions
View functions are usually defined in the views.py file of each application. The function defined in the view must have a request parameter. View processing complete request to return an instance of HttPResponse object
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def index(request):
return HttpResponse('index1!!!')
def index2(request):
return HttpResponse('index2!!!')
2. Configure URL
Purpose: to establish the corresponding relationship between url and view function.
Steps: Copy the urls.py file in the project to the application folder.
In the old version of django, the url() function is used for routing configuration, and the new version uses path() and re_path().
The path() and re_path() parameters of url routing in Django2.x are explained, refer to https://blog.csdn.net/qq_39197555/article/details/114006418