脚本专栏 
首页 > 脚本专栏 > 浏览文章

Python urls.py的三种配置写法实例详解

(编辑:jimmy 日期: 2024/11/30 浏览:3 次 )

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/("htmlcode">
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中类变量与成员变量的使用注意点总结
下一篇:Python HTTP客户端自定义Cookie实现实例
微软与英特尔等合作伙伴联合定义“AI PC”:键盘需配有Copilot物理按键
几个月来,英特尔、微软、AMD和其它厂商都在共同推动“AI PC”的想法,朝着更多的AI功能迈进。在近日,英特尔在台北举行的开发者活动中,也宣布了关于AI PC加速计划、新的PC开发者计划和独立硬件供应商计划。
在此次发布会上,英特尔还发布了全新的全新的酷睿Ultra Meteor Lake NUC开发套件,以及联合微软等合作伙伴联合定义“AI PC”的定义标准。
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网 网站地图 SiteMap