Configuration of page jumps (django)

1. Settings of the views.py file

In order for the newly created page to have a correct URL address, we must create a function in views.py, which is the view file, which returns the name of the page you want to jump to.

from django.shortcuts import render

def render_list(request):
    return render(request, 'APP/specified page.html') 
from django.shortcuts import render refers to importing the render request from the django.shortcuts module.
def render_list(request):
   return render(request, 'APP/specified page.html') This is a Python function, and the parameter request request is required.

 2. Settings of the urls.py file

Corresponding to the settings in views.py, in the urls.py file, we need to call the newly created function in view.py, the user request will access the URL address, and then access your newly created page through the function in the view view.

from django.conf.urls import url, include
from django.contrib import admin


urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^$', views.render_index),
    url(r'^specified page/$', views.render_list)
]
from django.conf.urls import url, include
from django.contrib import admin
Introduce url from the django.conf.urls module, and include these two commands.
urlpatterns = [
    url(r'^admin/', admin.site.urls), the URL address of this background.
    url(r'^$', views.render_index), this is the URL address of the home page.
    url(r'^specified page/$', views.render_list) This is the URL address of the new page.
]

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326802922&siteId=291194637