没有错误,但是模板中没有类别的值/显示
forms.py:
class UploadwContentForm(forms.ModelForm):
TYPE_OF_FILE_CHOICES = (
('CATEGORY 1','CATEGORY 1'),
('CATEGORY 1','Catergoty 2'),
('CATEGORY 1','Catergoty 3'),
('CATEGORY 1','Catergoty 4')
)
title = forms.CharField(widget=forms.TextInput(
attrs={
'class': 'form-control',
'placeholder' : 'Enter your title here:'
}
) )
category = forms.ChoiceField(widget=forms.Select(attrs={
'class' : 'btn btn-danger dropdown-toggle'
}), choices=TYPE_OF_FILE_CHOICES)
views.py:
def uploadlist(request):
uploadwcontent = UploadwContent.objects.all()
return render(request, 'upload/uploadlist.html', {
'uploadwcontent' : uploadwcontent
})
template_views.py
{% for uploadwcontent in uploadwcontent%}
<td> {{uploadwcontent.title}}</td>
<td>{{ uploadwcontent.author}}</td>
<td>
<a href="{{ uploadwcontent.pdf.url}}" class="btn-primary btn-sm "target="_blank">
Download PDF
</a>
</td>
<td>
{{form.get_category_display}}
</td>
</tr>
{% endfor %}
答案 0 :(得分:0)
更改视图以使用
const nDates = dates.map(date => new Date(date));
console.log(nDates);
并将模板中的for循环更改为
render(request, 'upload/uploadlist.html', { 'uploadwcontents' : uploadwcontent })
您的for循环必须采用{% for uploadwcontent in uploadwcontents %}
样式