“已登录” templatetag 不渲染

发布于 2024-07-08 07:51:33 字数 495 浏览 8 评论 0原文

由于某种原因,模板标签不会在 django admin 的模板中呈现。

这段代码来自: http://docs .djangoproject.com/en/dev/ref/templates/api/?from=olddocs#shortcut-for-simple-tags

{% if is_logged_in %}Thanks for logging in!{% else %}Please log in.{% endif %}

当放置在管理index.html中时,如果用户登录,它会显示“请登录”

与模板标签相同,无法显示任何应用程序,无法执行任何操作。 没有错误/它们也没有得到处理

for some reason, templatetags do not render in templates for django admin.

with this snippet from:
http://docs.djangoproject.com/en/dev/ref/templates/api/?from=olddocs#shortcut-for-simple-tags

{% if is_logged_in %}Thanks for logging in!{% else %}Please log in.{% endif %}

when placed in admin index.html, if a user is logged in, it shows "Please log in"

same with templatetags, can not get any app ones to show, do anything. there is no error/they do not get processed either

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

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

发布评论

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

评论(2

哆啦不做梦 2024-07-15 07:51:33

这只是一个示例,is_logged_in 变量实际上并未在任何模板中定义,除非您将其放入上下文中。

如果您添加该行并得到Please log in.,则确实意味着该标记正在呈现。 如果它在 if 中失败并转到 else ,那么它显然正在运行。 不过,您需要在模板中找到可以实际用于 if 情况的内容。 我没有弄乱 newforms-admin 中的管理模板,但取决于它们是否使用 RequestContext 以及您启用的 ContextProcessors - 您可能会说 {% if not request.user.is_anonymous %} .. . 或类似的东西。

That's only an example, the is_logged_in variable is not actually defined in any templates unless you put it in the context.

If you added that line and got Please log in. it does mean that the tag is rendering. If it fails the if and goes to the else it is clearly being run. You need to find something in the template you can actually use for the if case, though. I haven't messed with the admin templates in newforms-admin, but depending if they use RequestContext and on which ContextProcessors you have enabled - you might be able to say {% if not request.user.is_anonymous %} ... or something similar.

南汐寒笙箫 2024-07-15 07:51:33

我刚刚尝试了这个:

request.user.is_authenticated

就在模板中,并且按照我们的意愿工作了!

I just tried this one:

request.user.is_authenticated

Right in the template and just worked as we wish!

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