如何在HTML模板中使用Django使用多级{%url%} - 基于类的视图
IM利用基于类的视图:我有一个应用程序,该应用程序中有1个URLS文件,2个Sublevels URLS文件和1个视图文件,我的最后一个Sublevel URLS文件
portfolio_menu.urls:
app_name = 'portfolio'
urlpatterns = [
path('test', include('store.urls', namespace='store')),
path('', views.menu),
]
store.urls:store.urls:
app_name = 'store
urlpatterns = [
path('', include('product.urls', namespace='product')),
]
product.urls:
app_name = 'product'
urlpatterns = [
path('', views.ProductListView.as_view(), name='list'),
]
funcion: funcion我想获得的funcion ,但不知道Sintax:
<a href="{%url portfolio:store:product:list%}"></a> #I wish something like that
Im utilizing class based views: I have an app that has 1 urls file in app, 2 sublevels urls files and 1 view file from my last sublevel urls file
portfolio_menu.urls:
app_name = 'portfolio'
urlpatterns = [
path('test', include('store.urls', namespace='store')),
path('', views.menu),
]
store.urls:
app_name = 'store
urlpatterns = [
path('', include('product.urls', namespace='product')),
]
product.urls:
app_name = 'product'
urlpatterns = [
path('', views.ProductListView.as_view(), name='list'),
]
the funcion I want to get, but don't know the sintax:
<a href="{%url portfolio:store:product:list%}"></a> #I wish something like that
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
仅使用其中之一:
namepace
或app_name
。应该更清楚。在模板中,它应完全按照您的需求工作,但将其用作以下字符串:
''
。Use only one of these:
namespace
orapp_name
. It should be clearer.In template it should work exactly as you wanted, but use it as a string with:
''
.