欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python urls.py的三種配置寫法實例詳解

 更新時間:2017年04月28日 15:14:12   投稿:lqh  
這篇文章主要介紹了Python urls.py的三種配置寫法實例詳解的相關(guān)資料,需要的朋友可以參考下

urls.py的配置寫法一般有三種方式。

1. 第一種是導(dǎo)入視圖的方式,就是 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' ) 

大同小異。

下面來個詳細(xì)的代碼總結(jié):

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')),
)

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關(guān)文章

  • Python?Matplotlib基本用法詳解

    Python?Matplotlib基本用法詳解

    Matplotlib?是Python中類似?MATLAB?的繪圖工具,熟悉?MATLAB?也可以很快的上手?Matplotlib,這篇文章主要介紹了Python?Matplotlib基本用法,需要的朋友可以參考下
    2023-03-03
  • Django實現(xiàn)跨域的2種方法

    Django實現(xiàn)跨域的2種方法

    這篇文章主要介紹了Django實現(xiàn)跨域的2中方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2019-07-07
  • 基于python中pygame模塊的Linux下安裝過程(詳解)

    基于python中pygame模塊的Linux下安裝過程(詳解)

    下面小編就為大家?guī)硪黄趐ython中pygame模塊的Linux下安裝過程(詳解)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-11-11
  • 使用Python實現(xiàn)簡單的爬蟲框架

    使用Python實現(xiàn)簡單的爬蟲框架

    爬蟲是一種自動獲取網(wǎng)頁內(nèi)容的程序,它可以幫助我們從網(wǎng)絡(luò)上快速收集大量信息。下面我們將學(xué)習(xí)如何使用 Python 編寫一個簡單的爬蟲框架,感興趣的可以了解一下
    2023-05-05
  • 使用Pandas的Series方法繪制圖像教程

    使用Pandas的Series方法繪制圖像教程

    今天小編就為大家分享一篇使用Pandas的Series方法繪制圖像教程,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-12-12
  • Python selenium 三種等待方式詳解(必會)

    Python selenium 三種等待方式詳解(必會)

    這篇文章主要介紹了Python selenium 三種等待方式詳解(必會)的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2016-09-09
  • Python環(huán)境配置實現(xiàn)pip加速過程解析

    Python環(huán)境配置實現(xiàn)pip加速過程解析

    這篇文章主要介紹了Python環(huán)境配置實現(xiàn)pip加速過程解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-11-11
  • pytorch使用voc分割數(shù)據(jù)集訓(xùn)練FCN流程講解

    pytorch使用voc分割數(shù)據(jù)集訓(xùn)練FCN流程講解

    這篇文章主要介紹了pytorch使用voc分割數(shù)據(jù)集訓(xùn)練FCN流程,圖像分割發(fā)展過程也經(jīng)歷了傳統(tǒng)算法到深度學(xué)習(xí)算法的轉(zhuǎn)變,傳統(tǒng)的分割算法包括閾值分割、分水嶺、邊緣檢測等等
    2022-12-12
  • Python守護進程用法實例分析

    Python守護進程用法實例分析

    這篇文章主要介紹了Python守護進程用法,實例分析了Python守護進程的功能及使用方法,需要的朋友可以參考下
    2015-06-06
  • python列表去重的二種方法

    python列表去重的二種方法

    這篇文章主要介紹了python列表去重的二種方法,第二種方法無法保持原有順序,需要的朋友可以參考下
    2014-02-02

最新評論