Django:嵌套URLS有困难

时间:2014-03-27 23:27:32

标签: python django django-urls django-registration

我正在尝试在安装django-registration app

后将我的网址连接在一起

我的主要项目名为Club,这里是 club / club / urls.py:

from django.conf.urls import patterns, include, url
from blog import views
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'club.views.home', name='home'),
    # url(r'^club/', include('club.foo.urls')),

    # Uncomment the admin/doc line below to enable admin documentation:
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    url(r'^admin/', include(admin.site.urls)),
    url(r'^addauthor$', views.addauthorView),
    url(r'^thanks/$', views.thanksView),
    url(r'^displayauthors/$', views.displayauthors),
    # registration links below
    url(r'^reg/', include('club.registration.urls')),

)   

这是我的俱乐部/ registration / urls.py:

from django.conf.urls import patterns, include, url

urlpatterns = patterns('',
url(r'^accounts/', include('registration.backends.default.urls')),
)

我正确连接这两个吗?或者还有另一种方法吗?

尝试在浏览器中访问http://127.0.0.1:8000/reg/accounts/login/时收到错误消息:

ImportError at /reg/accounts/login/
No module named registration.urls

1 个答案:

答案 0 :(得分:2)

您是否有注册""应用程序(即俱乐部/注册/网址)?不想成为一个混蛋;老老实实地想知道。有理由这样做,但如果你没有做出任何重大改变,可能只是很容易直接从根网址链接。

如果您只想使用django-registration app批发,您的根网址( club / club / urls.py )可以说:

url(r'^reg/', include('registration.backends.default.urls')),。请注意,您可以将r'^reg/'更改为您想要的网址。要链接到它,您将转到http://127.0.0.1:8000/reg/login

如果您确实有理由进行注册'应用程序(这意味着你有一个单独的俱乐部/注册/'目录),这也很好。你不需要俱乐部'在您的根网址包含链接( club / club / urls.py ):

url(r'^reg/', include('registration.urls')),

然后您的原始链接应该有效:http://127.0.0.1:8000/reg/accounts/login/