我对 django CMS 非常陌生,我正在尝试添加我的博客的工具栏
。
这是我的 cms_toolbar.py
文件
from cms.toolbar_base import CMSToolbar
from cms.toolbar_pool import toolbar_pool
from blog.models import BlogPluginModel
from cms.utils.urlutils import admin_reverse
class PollToolbar(CMSToolbar):
def populate(self):
menu = self.toolbar.get_or_create_menu(
'blog_pluginmodel', # a unique key for this menu
'blog', # the text that should appear in the menu
)
menu.add_modal_item(
name='Add a new blog', # name of the new menu item
url=admin_reverse('blog_pluginmodel'), # the URL it should open with
)
toolbar_pool.register(PollToolbar)
但在下面引发了我的错误:
NoReverseMatch at /en/
Reverse for 'blog_pluginmodel' not found. 'blog_pluginmodel' is not a valid view function or pattern name.
我不知道如何解决这个问题。在这种情况下任何人都可以帮助我吗?
反向管理实际上是什么?
最佳答案
这里是 documentation 的链接,这是 source code .
admin_reverse
的作用是解析 django 模型的管理(列表/添加/编辑) View ,以将其显示在 djangocms 模式中。
就您而言,类似这样的事情应该有效:
admin_reverse('blog_pluginmodel_changelist')
或
admin_reverse('blog_pluginmodel_add')
以更抽象的方式:reverse_admin('appname_modelname_adminview')
。
P.S.:我不确定插件模型是否真的是您想要通过工具栏访问的,但这是另一个讨论。
关于Django CMS 反向管理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58791729/