django做分页功能
django做分页功能?
不用from django.conf.urls import patterns, include, url# Uncomment the next two lines to enable the admin:# from django.contrib import admin# admin.autodiscover()urlpatterns = patterns('',# Examples:# url(r'^$', 'nowamagic.views.home', name='home'),# url(r'^nowamagic/', include('nowamagic.foo.urls')),# Uncomment the admin/doc line below to enable admin documentation:# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),# Uncomment the next line to enable the admin:# url(r'^admin/', include(admin.site.urls)),)前面也谈过,只要配置这么一条规则:[python] view plain copy print?(r'^hello/$', hello),就可以定义 /hello/ 路径显示 views.py 中的 hello 函数。模式包含了一个尖号(^)和一个美元符号($)。这些都是正则表达式符号,并且有特定的含义:上箭头要求表达式对字符串的头部进行匹配,美元符号则要求表达式对字符串的尾部进行匹配。^hello/$ 匹配 hello/ 字符串,即在网址 hello/ 找到 hello/ 后,使用 hello() 函数显示出来,如果没有'$'结尾,则网址中输入 hello1/; hello2/ 都会对应以 hello() 函数显示出来。hello 函数我们随便写写:[python] view plain copy print?from django.http import HttpResponse,Http404def hello(request): #每个视图函数至少要有一个参数,通常被叫作request。return HttpResponse("Hello NowaMagic!") #一个视图功能必须返回一个HttpResponse那么我需要显示首页,就是域名直接映射到某个 view 函数下,那么又怎么写呢?[python] view plain copy print?(r'^$', index),index 函数就是生成首页的 view 函数。顺便说下,在 view 函数里,return HttpResponseRedirect('../'):返回主页,即127.0.0.1。
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: django做分页功能
本文地址: https://pptw.com/jishu/63846.html