urls.py中url匹配的方式

方式一:

[root@iZ28cumdzmgZ muahao01]# vim urls.py

from django.conf.urls import patterns, include, url

from django.contrib import admin
from blog.views import index
urlpatterns = patterns(‘‘,
    # Examples:
    # url(r‘^$‘, ‘muahao01.views.home‘, name=‘home‘),
    # url(r‘^blog/‘, include(‘blog.urls‘)),

    url(r‘^blog/index/$‘, index),

)


方式二:


from django.conf.urls import patterns, include, url
from django.contrib import admin
#from blog.views import index
urlpatterns = patterns(‘‘,
    # Examples:
    # url(r‘^$‘, ‘muahao01.views.home‘, name=‘home‘),
    # url(r‘^blog/‘, include(‘blog.urls‘)),

    url(r‘^blog/index/$‘, ‘blog.views.index‘),
)

  

方式三:


from django.conf.urls import patterns, include, url
from django.contrib import admin
#from blog.views import index
urlpatterns = patterns(‘blog.views‘,
    # Examples:
    # url(r‘^$‘, ‘muahao01.views.home‘, name=‘home‘),
    # url(r‘^blog/‘, include(‘blog.urls‘)),

    url(r‘^blog/index/$‘, ‘index‘),
)

                 



通过url进行参数的传递:

[root@iZ28cumdzmgZ muahao01]# vim urls.py

from django.conf.urls import patterns, include, url
from django.contrib import admin
#from blog.views import index
urlpatterns = patterns(‘blog.views‘,
    # Examples:
    # url(r‘^$‘, ‘muahao01.views.home‘, name=‘home‘),
    # url(r‘^blog/‘, include(‘blog.urls‘)),

    url(r‘^blog/index/(?P<id>\d{2})/$‘, ‘index‘),
)                        
 

本文出自 “8176010” 博客,请务必保留此出处http://8186010.blog.51cto.com/8176010/1592565

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。