推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
erse
V2EX  ›  Python

问一下 django 的 url 问题

  •  
  •   erse · Sep 17, 2014 · 3613 views
    This topic created in 4397 days ago, the information mentioned may be changed or developed.
    我在工程中建了一个xiaqu的application,现在xiaqu的url配置如下:urlpatterns = patterns('',
    url(r'^$', 'xiaqu.views.first_page'),
    url(r'^staff/', 'xiaqu.views.staff'),
    )
    为啥我访问http://127.0.0.1:8000/xiaqu/staff/提示页面The current URL, xiaqu/staff/, didn't match any of these.
    求指点
    7 replies  •  2014-09-18 15:47:40 +08:00
    limuxy
        1
    limuxy  
       Sep 17, 2014 via Android   ❤️ 1
    Project的url把app的包括进去了吗?
    ChanneW
        2
    ChanneW  
       Sep 17, 2014
    确实不匹配,访问的是 "xiaqu/staff/"
    不知道 xiaqu 怎么来的,确定有这个的话,那就应该:

    urlpatterns = patterns('',
    url(r'^$', 'xiaqu.views.first_page'),
    url(r'^xiaqu/staff/', 'xiaqu.views.staff'),
    )
    ChanneW
        3
    ChanneW  
       Sep 17, 2014
    #site url
    urlpatterns = patterns('',
    url(r'^xiaqu/', include('xiaqu.url')),
    )

    #xiaqu url
    urlpatterns = patterns('',
    url(r'^$', 'xiaqu.views.first_page'),
    url(r'^staff/', 'xiaqu.views.staff'),
    )
    ChanneW
        4
    ChanneW  
       Sep 17, 2014
    或者是这里 url(r'^xiaqu/', include('xiaqu.url')), 多加了 $
    erse
        5
    erse  
    OP
       Sep 17, 2014
    @limuxy 已经把xiaqu的app加进去了
    @ChanneW 好像就这样好了
    我也想不明白什么原因,
    gevin
        6
    gevin  
       Sep 17, 2014   ❤️ 1
    url(r'^staff/', 'xiaqu.views.staff'),这里没加$
    改成
    url(r'^staff/$', 'xiaqu.views.staff'),
    erse
        7
    erse  
    OP
       Sep 18, 2014
    @gevin 好像加了这个$也不行,我试了一下,后来不知道怎么自己就莫名其妙的好了,也没修改什么。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2422 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 01:14 · PVG 09:14 · LAX 18:14 · JFK 21:14
    ♥ Do have faith in what you're doing.