我有一个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 的
为什么呢,应该如何配置~
from django.conf.urls import patterns, include, url
from views import *
urlpatterns = patterns(
url(r'^hello/$', hello),
)
第二个url写法是有问题的,导入模块写法应该是from app.views import hello
这个格式,在django中,都应该这种导入方法。
另入,像第二个,我平时是这么写的:
url(r'^hello/$', 'app.viwes.hello`),
多看下django book里面的url写法。
应该这样写"url(r'^funnytest/', include('funnytest.urls',namespace="funnytest")),"
http://stackoverflow.com/questions/12...