why my django url conf failed to include another apps url module

I have a project whose root url conf content is :

 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 is an app of this project ,In funnytest I write a module urls.py to configure request of this app :

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

AS I visit localhost/funnytest/hello/ there return a dispath error which say that there has no such pattern

While I visit localhost/helloworld , it works well.

为什么呢,应该如何配置~

Answers


If you look at the definition of the patterns function:

def patterns(prefix, *args):
    pattern_list = []
    for t in args:
        if isinstance(t, (list, tuple)):
            t = url(prefix=prefix, *t)
        elif isinstance(t, RegexURLPattern):
            t.add_prefix(prefix)
        pattern_list.append(t)
    return pattern_list

You'll see that patterns takes an argument 'prefix' before the list of url patterns.

Try the following in both files: Add an empty string as the first argument to patterns.

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

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

Need Your Help

while loop with form with checkbox php not updating based on database details

php mysql

I have a while loop which is display all information correctly, I want a checkbox allowing me to mark each member of the loop as completed in the database, I don't really know where to start with t...

Constructing a QIcon through a QPainter in PyQT

python icons pyqt pyqt4

I know this is possible, but I cannot for the life of me get the proper code to work. What I want is very simple: a monochromatic rectangle, size, say 20x20 constructed (presumably) through a QPain...