urls.py的配置写法一般有三种方式。
1. 第一种是导入视图的方式,就是 The Django Book 里面样例的写法:
from blog.vIEws import index url(r'^Nowamagic/',index)
2. 第二种方法是视图处理方法,看代码就知道是怎么回事了。
url(r'^Nowamagic/','test.vIEws.index')
3. 第三种是把模型与视图写在前缀里。
urlpatterns = patterns('blog.vIEws',url(r'^Nowamagic$','index' ) url(r'^Nowamagic/\d{2}/$','index') url(r'^Nowamagic/(?P<ID>\d{2})/$','index' )
大同小异。
下面来个详细的代码总结:
from django.conf.urls.defaults import *urlpatterns = patterns('',# test_clIEnt modeltest urls (r'^test_clIEnt/',include('modeltests.test_clIEnt.urls')),(r'^test_clIEnt_regress/',include('regressiontests.test_clIEnt_regress.urls')),# file upload test vIEws (r'^file_uploads/',include('regressiontests.file_uploads.urls')),# Always provIDe the auth system login and logout vIEws (r'^accounts/login/$','django.contrib.auth.vIEws.login',{'template_name': 'login.HTML'}),(r'^accounts/logout/$','django.contrib.auth.vIEws.logout'),# test URLconf for {% url %} template tag (r'^url_tag/',include('regressiontests.templates.urls')),# django built-in vIEws (r'^vIEws/',include('regressiontests.vIEws.urls')),# test URLconf for mIDdleware tests (r'^mIDdleware/',include('regressiontests.mIDdleware.urls')),# admin vIEw tests (r'^test_admin/',include('regressiontests.admin_vIEws.urls')),(r'^generic_inline_admin/',include('regressiontests.generic_inline_admin.urls')),# admin Widget tests (r'Widget_admin/',include('regressiontests.admin_Widgets.urls')),(r'^utils/',include('regressiontests.utils.urls')),# test URLconf for syndication tests (r'^syndication/',include('regressiontests.syndication.urls')),# conditional get vIEws (r'condition/',include('regressiontests.conditional_processing.urls')),# mIDdleware exceptions tests (r'mIDdleware_exceptions/',include('regressiontests.mIDdleware_exceptions.urls')),# special headers vIEws (r'special_headers/',include('regressiontests.special_headers.urls')),)
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
总结以上是内存溢出为你收集整理的Python urls.py的三种配置写法实例详解全部内容,希望文章能够帮你解决Python urls.py的三种配置写法实例详解所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)