时间:2021-05-22
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')),)感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
1,urls.py内容:fromdjango.conf.urlsimporturlfromdjango.contribimportadminfrommyAppi
urls.py:URLdispatcher(路由配置文件)URL配置(URLconf)就像是Django所支撑网站的目录。它的本质是URL模式以及要为该URL模
一个Django工程中多数情况下会存在多个应用,如何针对多个应用的url进行配置呢,有以下两种方案:1、在Django工程的urls.py中针对每个应用分别配置
1.在myblog中的urls.py中fromdjango.urlsimportincludefromdjango.conf.urlsimporturlurlp
django后台管理系统的使用检查配置文件检查根urls.py文件启动项目,浏览器输入ip端口/admin如:127.0.0.1/8000/admin回车注册后