我是python的新手,在这里我需要将{{i}}增大为1,因此它是这样的:2017-2018
而不是2017-2017+1
。我在下面分享我的代码,请帮帮我!!预先感谢。
views.py
from django.shortcuts import render
from django.http import HttpResponse
from mainapp.models import query
import datetime
def index(request):
now = datetime.datetime.now()
cdt = now.year
if cdt:
cdt = range(2017, int(cdt))
return render(request,"mainapp/base.html",{'yy':cdt})
base.html
<html>
<head><title>{% block title %}AmeyaKrishi Version 2{% endblock %}</title></head>
<body>
<h2>AmeyaKrishi V2 (testing mode): All University Filter</h2><hr>
<p>
<form action="getFarmer" method="post">
<select class="form-control" name="season">
<option value="0">-- Select Year --</option>
<option value="333">All Data</option>
{% for i in yy %}
<option value="{{i}}">{{i}} - {{i}}+1</option>
{% endfor %}
</select>
<input type="submit" value="Search >>">
</form>
</p>
{% block content %}
{% endblock %}
</body>
</html>
浏览器输出:(在本地服务器上) enter image description here
答案 0 :(得分:0)
您可以使用内置模板标签的add
<option value="{{i}}">{{i}} - {{i|add:"1"}}</option>