【发布时间】:2020-12-24 14:00:36
【问题描述】:
我的代码:
{% if request.user.is_staff %}
{% extends "base.html" %}
{% load crispy_forms_tags %}
{% block content %}
<div class="content-section">
<form method="POST">
{% csrf_token %}
<fieldset class="form-group">
<legend class="border-bottom mb-4">
Create A Post
</legend>
{{ form|crispy }}
</fieldset>
<div class="form-group">
<button class="btn btn-outline-info" type="submit">
Post
</button>
</div>
</form>
</div>
{% endblock content %}
{% else %}
<head>
<meta http-equiv="refresh" content="5; url=/" />
</head>
<body>
<h1>Restricted Access To Staff!</h1>
<p>You will be redirected to the home page in 5 seconds</p>
</body>
{% endif %}
我不知道为什么它不起作用,这可能与 {% if request.user.is_staff %} 位有关吗?
【问题讨论】:
-
{% extends %}应该始终是 first 模板标签,因此不允许在{% if %} ... {% else %}子句中移动。
标签: python django django-views django-templates django-tagging