推荐学习书目
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 · Sep 10, 2012 · 3521 views
    This topic created in 5017 days ago, the information mentioned may be changed or developed.
    我有一个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 replies    1970-01-01 08:00:00 +08:00
    hellmimiworld
        1
    hellmimiworld  
       Sep 10, 2012
    ----------------------------------------------------------------------------------------------
    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
       Sep 10, 2012
    @hellmimiworld 这个参数不是必须的吧?
    另外我加上了还是没用~
    stackpop
        3
    stackpop  
    OP
       Sep 10, 2012
    @hellmimiworld 谢谢,解决了,都加上就OK。不过不太理解这里,我一直以为那个是可以删除的。
    clww
        4
    clww  
       Sep 10, 2012
    funnytest这个app加到settings.py里了没?
    stackpop
        5
    stackpop  
    OP
       Sep 10, 2012
    @clww 加了的,谢谢,问题解决了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2905 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 45ms · UTC 05:10 · PVG 13:10 · LAX 22:10 · JFK 01:10
    ♥ Do have faith in what you're doing.