template.html模板邏輯不正常
<tr><td>
{% if place %}
<input type="checkbox" id="select_all"/>Display all<br />
<hr style="width: 150px;margin: 8px 0;">
{% for value in place %}
{{ value }}
{% endfor %}
{% endif %}</td></tr>
<tr><td>{% include "buttons/addalist.html" %} {% include "buttons/save.html" %}</td></tr>
views.py
def type_list(request,type_id):
user = request.user
try:
type_list = Types.objects.get(user=user.id, id=type_id)
except:
return redirect('incident.views.incident_types')
if request.method == 'POST':
report_type = TypeSettingsForm(request.POST)
if 'title' in request.POST and report_type.is_valid():
if request.POST['title'].strip():
result = report_type.save(commit=False)
result.user = user
result.is_active = True
result.parent_type_id = type_id
result.save()
else:
place = TypeSelectionForm(type_id, request.POST)
if types.is_valid() and 'status' in request.POST:
types.save(type_id, request.POST)
type_list.is_active = eval(request.POST['status'])
type_list.save()
return redirect('incident.views.incident_types')
place = TypeSelectionForm(type_id)
return render(request, 'incident/type_list.html',
{
'about_menu': True,
'type_list': type_list,
'place':place
})
點擊addalist按鈕,值越來越保存並在模板中顯示。
但是最初,如果它們沒有從for循環顯示的值,則帶有複選框的Display All
不應該顯示。如果輸入了for循環的單個值Display All with display box will come display.It is a small logical錯誤,但我沒有得到this.Help非常感謝。
目前發生了什麼?你已經告訴我們會發生什麼,但目前沒有發生什麼?我認爲即使'place'中沒有值,也會顯示'Display All'? –