django 注册 redux URL 受到 url 的影响,具有多个查询参数
django registration redux URL's being effected by url with multiple query parameters
我的 Url 由 django registration redux 提供,当使用以下 url 时不起作用:
url(r'^(?P<username>\w+)/(?P<slug>[-\w]+)/$', views.project_page, name='user_project'),
但是如果我像这样向 url 添加另一个级别,它们就会起作用:
url(r'^projects/(?P<username>\w+)/(?P<slug>[-\w]+)/$', views.project_page, name='user_project'),
如果可能的话,我不想在其中添加额外的项目/url 级别。为什么它会影响 django 注册 redux url,我该如何解决?任何帮助将不胜感激:-)
项目urls
from django.conf.urls import patterns, include, url
from django.contrib import admin
from django.conf import settings
from registration.backends.simple.views import RegistrationView
class MyRegistrationView(RegistrationView): #redirects to home page after registration
def get_success_url(self,request, user):
return '/register_profile'
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'', include('howdidu.urls')),
url(r'^accounts/register/$', MyRegistrationView.as_view(), name='registration_register'), #redirects to home page after registration
(r'^accounts/', include('registration.backends.simple.urls')),
)
# media
if settings.DEBUG:
urlpatterns += patterns(
'django.views.static',
(r'^media/(?P<path>.*)',
'serve',
{'document_root': settings.MEDIA_ROOT}), )
应用urls
from django.conf.urls import patterns, url
from howdidu import views
from django.contrib.auth.decorators import login_required
urlpatterns = patterns('',
url(r'^$', views.index, name='index'),
url(r'^register_profile/$', views.register_profile, name='register_profile'),
url(r'^update_profile/$', views.update_profile, name='update_profile'),
url(r'^create_project/$', login_required(views.CreateProject.as_view()), name='create_project'),
url(r'^(?P<username>\w+)/$', views.profile_page, name='user_profile'),
url(r'^(?P<username>\w+)/(?P<slug>[-\w]+)/$', views.project_page, name='user_project'),
)
问题是你的 url 订购,看看这个:
url(r'^admin/', include(admin.site.urls)),
url(r'', include('howdidu.urls')),
url(r'^accounts/register/$', MyRegistrationView.as_view(), name='registration_register'), #redirects to home page after registration
url(r'^accounts/', include('registration.backends.simple.urls')),
尤其是这个:
url(r'', include('howdidu.urls')),
这个 url 匹配所有内容,所以基本上 Django 将从上到下查找,如果在 url(r'', include('howdidu.urls'))
之前没有找到任何匹配项,它将匹配任何内容。这意味着你永远不会匹配
url(r'^accounts/register/$', MyRegistrationView.as_view(), name='registration_register'), #redirects to home page after registration
url(r'^accounts/', include('registration.backends.simple.urls')),
修复它的一种方法是将 url(r'', include('howdidu.urls'))
放在 url 的最底部:
url(r'^admin/', include(admin.site.urls)),
url(r'^accounts/register/$', MyRegistrationView.as_view(), name='registration_register'), #redirects to home page after registration
url(r'^accounts/', include('registration.backends.simple.urls')),
url(r'^', include('howdidu.urls')),
另一种方法是为 url(r'^', include('howdidu.urls'))
设置另一个 url 级别:
url(r'^admin/', include(admin.site.urls)),
url(r'^howdidu/', include('howdidu.urls')),
url(r'^accounts/register/$', MyRegistrationView.as_view(), name='registration_register'), #redirects to home page after registration
url(r'^accounts/', include('registration.backends.simple.urls')),
我的 Url 由 django registration redux 提供,当使用以下 url 时不起作用:
url(r'^(?P<username>\w+)/(?P<slug>[-\w]+)/$', views.project_page, name='user_project'),
但是如果我像这样向 url 添加另一个级别,它们就会起作用:
url(r'^projects/(?P<username>\w+)/(?P<slug>[-\w]+)/$', views.project_page, name='user_project'),
如果可能的话,我不想在其中添加额外的项目/url 级别。为什么它会影响 django 注册 redux url,我该如何解决?任何帮助将不胜感激:-)
项目urls
from django.conf.urls import patterns, include, url
from django.contrib import admin
from django.conf import settings
from registration.backends.simple.views import RegistrationView
class MyRegistrationView(RegistrationView): #redirects to home page after registration
def get_success_url(self,request, user):
return '/register_profile'
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'', include('howdidu.urls')),
url(r'^accounts/register/$', MyRegistrationView.as_view(), name='registration_register'), #redirects to home page after registration
(r'^accounts/', include('registration.backends.simple.urls')),
)
# media
if settings.DEBUG:
urlpatterns += patterns(
'django.views.static',
(r'^media/(?P<path>.*)',
'serve',
{'document_root': settings.MEDIA_ROOT}), )
应用urls
from django.conf.urls import patterns, url
from howdidu import views
from django.contrib.auth.decorators import login_required
urlpatterns = patterns('',
url(r'^$', views.index, name='index'),
url(r'^register_profile/$', views.register_profile, name='register_profile'),
url(r'^update_profile/$', views.update_profile, name='update_profile'),
url(r'^create_project/$', login_required(views.CreateProject.as_view()), name='create_project'),
url(r'^(?P<username>\w+)/$', views.profile_page, name='user_profile'),
url(r'^(?P<username>\w+)/(?P<slug>[-\w]+)/$', views.project_page, name='user_project'),
)
问题是你的 url 订购,看看这个:
url(r'^admin/', include(admin.site.urls)),
url(r'', include('howdidu.urls')),
url(r'^accounts/register/$', MyRegistrationView.as_view(), name='registration_register'), #redirects to home page after registration
url(r'^accounts/', include('registration.backends.simple.urls')),
尤其是这个:
url(r'', include('howdidu.urls')),
这个 url 匹配所有内容,所以基本上 Django 将从上到下查找,如果在 url(r'', include('howdidu.urls'))
之前没有找到任何匹配项,它将匹配任何内容。这意味着你永远不会匹配
url(r'^accounts/register/$', MyRegistrationView.as_view(), name='registration_register'), #redirects to home page after registration
url(r'^accounts/', include('registration.backends.simple.urls')),
修复它的一种方法是将 url(r'', include('howdidu.urls'))
放在 url 的最底部:
url(r'^admin/', include(admin.site.urls)),
url(r'^accounts/register/$', MyRegistrationView.as_view(), name='registration_register'), #redirects to home page after registration
url(r'^accounts/', include('registration.backends.simple.urls')),
url(r'^', include('howdidu.urls')),
另一种方法是为 url(r'^', include('howdidu.urls'))
设置另一个 url 级别:
url(r'^admin/', include(admin.site.urls)),
url(r'^howdidu/', include('howdidu.urls')),
url(r'^accounts/register/$', MyRegistrationView.as_view(), name='registration_register'), #redirects to home page after registration
url(r'^accounts/', include('registration.backends.simple.urls')),