以下问题的解决方案是什么?
错误在第10行!
Error during template rendering
In template C:\Users\farib\Desktop\Python\classProject\signup\templates\services.html, error at line 10
Could not parse the remainder: '(airquality' from '(airquality'
1 {% extends "layout.html" %}
2 {% block content %}
3 <h1 style="color:rgb(51, 48, 51)">Services</h1>
4 <form id="contactForm" method="post" action="services" class="needs-validation">
5 {% csrf_token %}
6 {{ servicesform }}
7 <input id="sendBtn" type="submit" class="btn btn-primary" value="Analyze">
8 </form>
9 <h3>Address: {{ address }}, City: {{ city }}, Country: {{ country }}, Latitude: {{ latitude }}, Longitude: {{ longitude }}</h3>
10 {% if airquality < 50 %}
11 <h3 style="background-color: green;">Air Quality: {{ airquality }}</h3>
12 {% elif (airquality >= 51) and (airquality < 100) %}
13 <h3 style="background-color: yellow;">Air Quality: {{ airquality }}</h3>
14 {% elif (airquality >= 101) and (airquality < 150) %}
15 <h3 style="background-color: orange;">Air Quality: {{ airquality }}</h3>
16 {% elif (airquality >= 151) and (airquality < 200) %}
17 <h3 style="background-color: red;">Air Quality: {{ airquality }}</h3>
18 {% elif (airquality >= 201) and (airquality < 300) %}
19 <h3 style="background-color: purple;">Air Quality: {{ airquality }}</h3>
20 {% elif airquality >= 301 %}
我试图根据变量生成不同的html/css代码,但失败了。
我安装的应用程序还有:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'main',
'signup'
]
我的源代码如下:
{% extends "layout.html" %}
{% block content %}
<h1 style="color:rgb(51, 48, 51)">Services</h1>
<form id="contactForm" method="post" action="services" class="needs-validation">
{% csrf_token %}
{{ servicesform }}
<input id="sendBtn" type="submit" class="btn btn-primary" value="Analyze">
</form>
<h3>Address: {{ address }}, City: {{ city }}, Country: {{ country }}, Latitude: {{ latitude }}, Longitude: {{ longitude }}</h3>
{% if airquality < 50 %}
<h3 style="background-color: rgb(0, 228, 0);">Air Quality Index: {{ airquality }}</h3>
{% elif (airquality >= 51) and (airquality < 100) %}
<h3 style="background-color: yellow;">Air Quality Index: {{ airquality }}</h3>
{% elif (airquality >= 101) and (airquality < 150) %}
<h3 style="background-color: rgb(255, 126, 0);">Air Quality Index: {{ airquality }}</h3>
{% elif (airquality >= 151) and (airquality < 200) %}
<h3 style="background-color: red;">Air Quality Index: {{ airquality }}</h3>
{% elif (airquality >= 201) and (airquality < 300) %}
<h3 style="background-color: rgb(143, 63, 151);">Air Quality Index: {{ airquality }}</h3>
{% elif airquality >= 301 %}
<h3 style="background-color: rgb(126, 0, 35 );">Air Quality Index: {{ airquality }}</h3>
{% endif %}
编辑:问题是我把括号放在了elif块中!
2条答案
按热度按时间wvt8vs2t1#
Django模板不允许在if标签中使用括号!联系我们
线索在错误的最后一部分:
无法分析其余部分:'(airquality'从'(airquality'
所以错误实际上在第12行。
omtl5h9j2#
可能忘记关闭{% endif %}或任何其他关闭标记