views.py-
def SubCategoryList(request):
subcategory_form = SubcategoryForm(request.POST or None)
context ={
'form' : subcategory_form
}
#print(SubcategoryForm.POST.Category_id)
if subcategory_form.is_valid():
#print("Hi")
print(subcategory_form.cleaned_data['Category_id'])
qs = SubCategory.objects.filter(cat_id=subcategory_form.cleaned_data['Category_id'])
data = {}
for qss in qs:
data[qss.subcategory_id] = qss.subcategory_name
for k,v in data.items():
print(data[k])
print(data)
return render(request,"Subcategory/cat_sub_list.html",data)
return render(request,"Subcategory/sub_list.html",context)
cat_sub_list.html-
{% for key,v in data.items %}
{{ v }}
{% endfor %}
sub_list.html
<form method='POST'> {% csrf_token%}
{{form}}
<button type="submit" class="btn btn-default">Submit</button>
</form>
{{form}}有一个整数输入字段。
输入值sub_list.html后,它将重定向到cat_sub_list.html。但解析后不打印数据(字典)的值。