网上有一些关于django定义传参数的信息资料,不过有点旧。一些使用正则表达式定义页码的格式,略显得麻烦。参考Django User guide手册介绍的方法,事情变得相对简单。url网址中使用<int:parameter>来表示传入整数参数。下面来试试该方法的示范和灵活应用。urls.py的urlpatterns定义Django url路径规则。news为app名称。假设翻页方式为:首页为index.html,其余页面按照逻辑计数器的基本规则定义,如第2页为p2.html,第3页为p3.html,以此类推。
"""financeok URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.1/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import includ