Python Django:嵌套URL时遇到问题

Python Django:嵌套URL时遇到问题,python,django,django-urls,django-registration,Python,Django,Django Urls,Django Registration,我正在尝试在安装后将我的URL连接在一起 我的主要项目是Club,这里是Club/Club/url.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 =

我正在尝试在安装后将我的URL连接在一起

我的主要项目是Club,这里是Club/Club/url.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')),

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

urlpatterns = patterns('',
url(r'^accounts/', include('registration.backends.default.urls')),
)
这是我的俱乐部/注册/url。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')),

)   
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

您有“注册”应用程序(即俱乐部/注册/url)的原因吗?不想成为一个混蛋;真想知道。这样做是有原因的,但是如果您没有做任何大的更改,那么直接从根url链接可能很容易

如果您只想批发使用django注册应用程序,您的根url配置(club/club/url.py)可能会说:

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

如果你确实有理由拥有一个“注册”应用程序(这意味着你有一个单独的“俱乐部/注册/”目录),那也没关系。您不需要在根url配置的include链接中使用“club”(club/club/url.py):

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


那么您的原始链接应该可以工作:
http://127.0.0.1:8000/reg/accounts/login/

您使用“注册”应用程序(即俱乐部/注册/url)有什么原因吗?嗯,我想我最终会有一个注册视图,把所有注册部分保存在一个文件夹里似乎是个好主意。这不是编写可重用代码的好方法吗?摘自django registration:提供了两个视图:registration.backends.default.views.RegistrationView和registration.backends.default.views.ActivationView。这些视图分别为django registration的base RegistrationView和ActivationView子类,并实现两步注册/激活过程。看起来文件夹是必要的,但我想URL本身不必如此。事实上,我希望我所有安装了pip的应用程序都有一个文件夹,这样就更清楚了。Shuggy您不需要项目中的文件夹。它将搜索您的项目,然后搜索django注册包。基本上,你是在借用django-registration设置的应用程序。这取决于软件包和你的需要。如您所示,django注册有一些视图。它还有一个默认的URL配置,您已经链接到它(
registration.backends.default.URL
)。这意味着您正在利用这些URL和它们调用的视图。看起来,至少django注册仍然需要您制作自己的模板。请参阅快速入门说明-“所需模板”