Django:管理员的永久链接

发布于 2024-07-16 03:21:52 字数 538 浏览 6 评论 0原文

我知道到达对象的链接模板如下所示:

"{{ domain }}/{{ admin_dir }}/{{ appname }}/{{ modelname }}/{{ pk }}"

是否有内置方法来获取对象的永久链接?

from django.contrib import admin

def get_admin_permalink(instance, admin_site=admin.site):
    # returns admin URL for instance change page
    raise NotImplemented

编辑

它似乎在 v1.1 admin 已命名 URL。 不幸的是它还没有发布。

I know the link template to reach an object is like following:

"{{ domain }}/{{ admin_dir }}/{{ appname }}/{{ modelname }}/{{ pk }}"

Is there a way built-in to get a permalink for an object?

from django.contrib import admin

def get_admin_permalink(instance, admin_site=admin.site):
    # returns admin URL for instance change page
    raise NotImplemented

EDIT

It seems in v1.1 admin has named URLs. Unfortunately it's not yet released.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

隱形的亼 2024-07-23 03:21:52

1.1 已发布,文档就在这里: http ://docs.djangoproject.com/en/dev/ref/contrib/admin/#admin-reverse-urls
http://docs.djangoproject.com/en/dev/ref /templates/builtins/#url

我也使用过它,每当您获取现有的管理 url 时都必须指定管理名称空间。

# in urls.py, assuming you have a customized view
url(r'foo/

在 1.1 中,每当获取管理 URL 时,您都必须指定“admin”命名空间。

, 'foo', name='foo_index'), # in the template, to get the admin url {% url admin:foo_index %}

在 1.1 中,每当获取管理 URL 时,您都必须指定“admin”命名空间。

1.1 is out, the doc is right here: http://docs.djangoproject.com/en/dev/ref/contrib/admin/#admin-reverse-urls
http://docs.djangoproject.com/en/dev/ref/templates/builtins/#url

I also used it a bit, the admin namespace will have to be specified whenever you are fetching an existing admin url.

# in urls.py, assuming you have a customized view
url(r'foo/

In 1.1, whenever an admin url is fetched, you'll have to specify the 'admin' namespace.

, 'foo', name='foo_index'), # in the template, to get the admin url {% url admin:foo_index %}

In 1.1, whenever an admin url is fetched, you'll have to specify the 'admin' namespace.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文