【问题标题】:Reverse model admin custom URLs反向模型管理员自定义 URL
【发布时间】:2017-02-08 07:48:07
【问题描述】:

在我的admin.py 文件中,我有:

def get_urls(self):
    urls = super(TextAdmin, self).get_urls()
    my_urls = patterns('',
        url(
            r'customfunc1',
            customfunc2,
            name='customfunc23',
        ),
    )
    return my_urls + urls

这将启用以下 URL:

http://localhost:8000/admin/text/customfunc1

它将执行函数customfunc2。我现在的问题是如何通过 reverse 引用这个 URL?

我试过了:

reverse("admin:text_customfunc1")
reverse("admin:text_customfunc2")
reverse("admin:text_customfunc3")
reverse("text:customfunc1")

但这些都不起作用。

【问题讨论】:

    标签: python django python-2.7 django-admin


    【解决方案1】:

    你有name='customfunc23',它在admin应用程序中,所以你应该使用:

    reverse('admin:customfunc23')
    

    【讨论】:

      猜你喜欢
      • 2011-11-28
      • 2021-06-07
      • 2014-07-11
      • 2017-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-01
      • 1970-01-01
      相关资源
      最近更新 更多