当通过另一个应用程序的URL调用一个函数的url时,django url配置无法重定向到特定的url

时间:2017-05-07 15:39:26

标签: python django url

我在这里使用两个应用程序。用户应用程序创建,删除,更新,登录和注册用户。而网络应用程序只是检查会话是否通过@login_required装饰器设置。我的基本模板位于根目录上。我有一个登录功能,我想从中调用登录。

我无法从network.urls

访问user.urls

任何帮助将不胜感激。

network.urls

from django.conf.urls import url, include
from . import views
from user import urls as user_urls
from user import views as user_views
#from django.contrib import admin

urlpatterns = [
    url(r'^$', views.IndexView.as_view()),
    url(r'^user/login/', include('user.urls', namespace='user')),
    url(r'^captcha', include('captcha.urls')),
    #url(r'^admin/', admin.site.urls),
]

user.urls

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

urlpatterns = [
    url(r'^login/', views.LoginView.as_view(), name='login'),
    url(r'^$', views.IndexView.as_view(), name="index"),
    #url(r'^register', views.RegisterView.as_view(), name='register')
]

现在我想从基本模板调用用户登录,即

<body>

<div class="container-fluid">
    <div class="row">
        <div id="top_pane" class="row">
            <div class="col-lg-2 text-left" style="padding-left:20px" id="home_logo"><a href="#" style="color:#fff">GS</a></div>
            <div class="col-lg-8 text-center" id="top_search">
                <form class="form-inline">
                    {%csrf_token%}
                    <input type="text" name="search" placeholder="Search" class="form-control">
                    <input type="submit" class="btn btn-info" value="Search">
                </form>
            </div>
            <div class="col-lg-1 text-right" style="padding-right:5px" id="login_logo">
                <a href="{%url 'user:login'%}" type="button" class="btn btn-default btn-sm">
                    <span class="glyphicon glyphicon-log-in"></span> Log in
                </a>
            </div>
            <div class="col-lg-1 text-left" style="padding-left:5px" id="signup_logo">
                <a href="#" type="button" class="btn btn-default btn-sm">
                <span class="glyphicon glyphicon-user"></span> Sign Up
                </a>
            </div>
        </div>
        <nav class="navbar navbar-inverse" style="border-radius:0px">

            <ul class="nav navbar-nav">
                <li class="active"><a href="#">Home</a></li>
                <li><a href="#">Page 1</a></li>
                <li><a href="#">Page 2</a></li>
                <li><a href="#">Page 3</a></li>
            </ul>

        </nav>
    </div>
    <div class="row">
        <div clas="col-lg-2">{%block left_nav %}{%endblock%}</div>
        <div class="col-lg-7">{%block container%}{%endblock%}</div>
        <div class="col-lg-3">{%block advertisement%}{%endblock%}</div>
    </div>
</div>

</body>

0 个答案:

没有答案