使用{%url' admin'应用程序django中的%}

时间:2017-07-15 20:22:52

标签: python django django-templates django-urls

我想使用{%url' admin'将用户移动到Django中的管理面板网站%}但问题是我在应用程序中渲染的模板,我不想在project / site / urls.py中重写url("^admin/",admin.site.urls)

这里是

project / urls.py

urlpatterns = [
url(r"^admin/", admin.site.urls, name="admin"),
url(r"^", include("core.urls")),]

project / site / urls.py

urlpatterns = [
url(r"^$",indexView.as_view() ,name="index" ),
]
accountspattenrns = {
url(r"^accounts/signup/$",signupView.as_view() ,name="signup" ),    
url(r"^accounts/login/$",loginView.as_view() ,name="login" ),    
url(r"^accounts/logout/$",logoutView.as_view() ,name="logout" ),    
url(r"^accounts/profile/$",ProfileView.as_view() ,name="profile" ),    
}
urlpatterns +=accountspattenrns

template.html

<li><a href="{% url 'admin' %}"><i class="fa fa-black-tie fa-2x"></i>
<div>Admin</div></a></li> 

错误:

Error i got

1 个答案:

答案 0 :(得分:10)

尝试使用管理员命名空间

来反转网址
SELECT
    user_name, item_description, item_quantity, item_unit, 
    item_standard_price, item_percent_discount, 
    CAST(item_quantity * (item_standard_price * (1-item_percent_discount/100.0)) AS DECIMAL(10,2)) AS items_price
FROM
    items_x_orders
    JOIN orders USING (order_id)
    JOIN items USING (item_id)
    JOIN users USING (user_id) ;

参考:Django docs