Django CMS 反向管理

标签 django django-cms

我对 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/

相关文章:

django - 反向 django 自定义管理站点 URL

python - 在 Windows 上为 django 开发设置 virtualenv,

python - Django 模板 : key, 值在 for 循环中不可能

Django FlatPages 与 Django-CMS

python - 在另一个页面中渲染 cms 页面

python - 相当于Python微框架的rails' "devise"?

python - 更快的开发 Rails 还是 Django?

Django 1.8 + CMS 错误 : django. db.utils.ProgrammingError:关系 "cms_cmsplugin"不存在

python - django-cms makemigrations错误: No module named 'packaging'

python - 国际化的 Django 应用程序恢复为英语