“已登录” templatetag 不渲染
由于某种原因,模板标签不会在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这只是一个示例,
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 theif
and goes to theelse
it is clearly being run. You need to find something in the template you can actually use for theif
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.我刚刚尝试了这个:
request.user.is_authenticated
就在模板中,并且按照我们的意愿工作了!
I just tried this one:
request.user.is_authenticated
Right in the template and just worked as we wish!