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
stackpop
V2EX  ›  Python

django的url配置求教

  •  
  •   stackpop ·
    sjtubinlong · 2012-09-10 18:53:29 +08:00 · 2837 次点击
    这是一个创建于 4239 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我有一个project 跟目录的root url conf 设置内容为:

    ----------------------------------------------------------
    from django.conf.urls import patterns, include, url
    import funnytest
    urlpatterns = patterns(
    url(r'^funnytest/', include('funnytest.urls')),
    url(r'^helloworld/', funnytest.views.hello),
    )
    -----------------------------------------------------------

    其中funnytest是其中一个app,funnytest 目录下设置了一个Urls, 内容为:
    ------------------
    from django.conf.urls import patterns, include, url
    from views import *
    urlpatterns = patterns(
    url(r'^hello/$', hello),
    )
    -------------------

    我访问 localhost/funnytest/hello/ 会报错,表示urls 中没有匹配的配置
    但是访问localhost/helloworld 是可以访问到view hello 的

    为什么呢,应该如何配置~
    5 条回复    1970-01-01 08:00:00 +08:00
    hellmimiworld
        1
    hellmimiworld  
       2012-09-10 20:12:59 +08:00
    ----------------------------------------------------------------------------------------------
    from django.conf.urls import patterns, include, url
    from views import *
    urlpatterns = patterns(
    url(r'^hello/$', hello),
    )
    ----------------------------------------------------------------------------------------------
    这里错了,应该是
    urlpatterns = patterns('',
    url(r'^hello/$',hello)
    )
    你的少了一个参数~
    stackpop
        2
    stackpop  
    OP
       2012-09-10 20:21:38 +08:00
    @hellmimiworld 这个参数不是必须的吧?
    另外我加上了还是没用~
    stackpop
        3
    stackpop  
    OP
       2012-09-10 20:23:30 +08:00
    @hellmimiworld 谢谢,解决了,都加上就OK。不过不太理解这里,我一直以为那个是可以删除的。
    clww
        4
    clww  
       2012-09-10 20:25:08 +08:00
    funnytest这个app加到settings.py里了没?
    stackpop
        5
    stackpop  
    OP
       2012-09-10 20:27:41 +08:00
    @clww 加了的,谢谢,问题解决了。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2764 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 04:07 · PVG 12:07 · LAX 21:07 · JFK 00:07
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.