[英]django controlcenter url name
while using django-controlcenter
package, I am trying to set a url in a html template to access a dashboard.在使用
django-controlcenter
controlcenter package 时,我试图在 html 模板中设置 url 以访问仪表板。
In my urlpattersn I have:在我的 urlpattersn 中,我有:
path('admin/dashboard/', controlcenter.urls, name='dashboard'),
In my settings, I have a set a dashboard:在我的设置中,我设置了一个仪表板:
CONTROLCENTER_DASHBOARDS = (
('admindash', 'myapp.dashboards.AdminDashboard'),
)
So for a url that normally resolves as /admin/dashboard/admindash
, what the template url should be?那么对于通常解析为
/admin/dashboard/admindash
的 url,模板 url 应该是什么? django.urls
include
would not work with the package and the issue would be to register a proper namespace. django.urls
include
不适用于 package,问题是注册一个正确的命名空间。 I directly tried {% url 'dashboard:admindash' %}
and {% url 'admindash' %}
but it returned a NoReverseMatch error.我直接尝试
{% url 'dashboard:admindash' %}
和{% url 'admindash' %}
但它返回了NoReverseMatch错误。
Are you trying to use this code?:您是否正在尝试使用此代码?:
{% url 'admindash' %}
For url namespace syntax should be <namespace>:<name>
.对于 url,命名空间语法应为
<namespace>:<name>
。 But you are using it in wrong order {% url 'dashboard:admindash' %}
.但是您以错误的顺序使用它
{% url 'dashboard:admindash' %}
。 Which should be {% url 'admindash:dashboard' %}
这应该是
{% url 'admindash:dashboard' %}
The current solution I came up with is by using a RedirectView
in urls:我想出的当前解决方案是在 url 中使用
RedirectView
:
from django.views.generic.base import RedirectView
urlspattersn=[
path('admin/dashboard/', controlcenter.urls),
path('admin/dashboard/', RedirectView.as_view(url='admindash/', permanent=False), name='admindash'),
]
and then calling in template:然后调用模板:
{% url 'admindash' %}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.