Django——隐藏某些用户的链接

发布于 2024-12-11 19:56:39 字数 168 浏览 0 评论 0原文

是否可以在 Django Web 应用程序上对那些无权单击链接的用户隐藏某些链接?

我敢打赌,有一种针对每个链接的方法可以检查用户是否有权单击该链接,然后根据该测试显示(或不显示)该链接。然而,当大量链接分布在一大堆网页上时,这可能会非常乏味。有没有什么方法可以通过设置或其他方式在整个网站上实现这一目标?

Is it possible, on a Django webapp, to hide certain links from those users who do not have the permission to click the link?

I bet there is a per-link way to check if the user has persmission to click the link, and then show the link (or not) based on that test. However, when there are a lot links spread across a whole bunch of web pages, that can be ridiculously tedious. Are there any ways to achieve this across the whole website with a setting or something?

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

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

发布评论

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

评论(2

御弟哥哥 2024-12-18 19:56:39

编写类似于 spaceless会检查其内容并删除所有不可访问的链接。这将使您不必手动触摸每个链接。

write a template tag similar to spaceless that goes over its contents and removes all links that are not accessible. this would save you from having to touch each link manually.

太阳公公是暖光 2024-12-18 19:56:39

可以编写一个自定义模板标签来接受链接 url,反转它,内省目标视图所需的权限,然后有条件地显示它。

您仍然必须触摸您想要像这样花哨的每个模板中的每个链接,这可能是一个丑陋的野兽。总而言之,如果您想出一种更集中的方式来控制访问,可能会更容易。

It might be possible to write a custom template tag that would accept a link url, reverse it, introspect what permissions were required for the target view, and then conditionally display it.

You'd still have to touch every link in every template that you wanted to make fancy like that, and it would probably be an ugly beast. All in all, it's probably easier if you come up with a more centralized way to control access.

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