Skip to main content
 首页 » 编程设计

python之反向模型管理员自定义 URL

2025年04月02日8xing901022

在我的 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") 

但这些都不起作用。

请您参考如下方法:

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

reverse('admin:customfunc23')