urls.py - 将 / 页面重定向到另一个应用

urls.py - redirect the / page to another app

这两天我一直在尝试将根页面“/”重定向到另一个 urls.py

在阅读了操作方法后,我写了这个:

url(r'^$', indlude('x.y.urls')),

这是我的 x.y.core urls.py :

url(r'^$', IndexPageView.as_view(), name='index'),

但是我收到 404 错误。

我尝试了很多类似的东西:

url(r'', indlude('x.y.urls'))

url(r'^$/', indlude('x.y.urls'))

并在 x.y.urls 中:

url(r'^$', IndexPageView.as_view(), name='index'),
url(r'', IndexPageView.as_view(), name='index'), 

让它工作的唯一方法是:

url(r'^$', IndexPageView.as_view()),

知道如何让它发挥作用吗?如果我直接将“/”重定向到 IndexPageView,一切正常,因此视图和模板是正确的。

project.urls 模式

url(r'^', include('some_app.urls', namespace='some_app')),

some_app.urls 模式

url(r'^$', IndexPageView.as_view(), name='index'),
url(r'^other/view/$', OtherView.as_view(), name='other_view'),

例如 IndexPageView 里面可能有什么

from django.core.urlresolvers import reverse

class IndexPageView(RedirectView):
    permanent = False

    def get_redirect_url(self, *args, **kwargs):
        if self.request.user is not None and self.request.user.is_superuser:
            return reverse('some_app:other_view')
        else:
            return '/accounts/login/'