V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2014-09-17 20:37:40 +08:00 · 2731 次点击
    这是一个创建于 3513 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我在工程中建了一个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 条回复    2014-09-18 15:47:40 +08:00
    limuxy
        1
    limuxy  
       2014-09-17 20:51:34 +08:00 via Android   ❤️ 1
    Project的url把app的包括进去了吗?
    ChanneW
        2
    ChanneW  
       2014-09-17 21:01:49 +08:00
    确实不匹配,访问的是 "xiaqu/staff/"
    不知道 xiaqu 怎么来的,确定有这个的话,那就应该:

    urlpatterns = patterns('',
    url(r'^$', 'xiaqu.views.first_page'),
    url(r'^xiaqu/staff/', 'xiaqu.views.staff'),
    )
    ChanneW
        3
    ChanneW  
       2014-09-17 21:06:25 +08:00
    #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  
       2014-09-17 21:11:43 +08:00
    或者是这里 url(r'^xiaqu/', include('xiaqu.url')), 多加了 $
    erse
        5
    erse  
    OP
       2014-09-17 21:30:48 +08:00
    @limuxy 已经把xiaqu的app加进去了
    @ChanneW 好像就这样好了
    我也想不明白什么原因,
    gevin
        6
    gevin  
       2014-09-17 21:53:37 +08:00   ❤️ 1
    url(r'^staff/', 'xiaqu.views.staff'),这里没加$
    改成
    url(r'^staff/$', 'xiaqu.views.staff'),
    erse
        7
    erse  
    OP
       2014-09-18 15:47:40 +08:00
    @gevin 好像加了这个$也不行,我试了一下,后来不知道怎么自己就莫名其妙的好了,也没修改什么。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2241 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 11:25 · PVG 19:25 · LAX 04:25 · JFK 07:25
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.