0
我的問題是,爲什麼窗體顯示沒有文件選擇對文件字段,即使當文件加載(以及如何糾正這一點)?Django窗體顯示沒有文件選擇
我有以下形式(相關位被用於FileInput小部件):
class StudentForm(forms.ModelForm):
class Meta:
model = Student
exclude = ['id',]
widgets = {
'user' : forms.HiddenInput(),
'first_name' : forms.TextInput(attrs={'class' : 'form-control'}),
'last_name' : forms.TextInput(attrs={'class' : 'form-control'}),
'email' : forms.EmailInput(attrs={'class' : 'form-control'}),
'majors' : forms.TextInput(attrs={'class' : 'form-control'}),
'university' : forms.TextInput(attrs={'class' : 'form-control'}),
'grad_year' : forms.TextInput(attrs={'class' : 'form-control',
'type' : 'number'}),
'resume' : forms.FileInput(attrs={'class' : 'form-control'}),
'transcript' : forms.FileInput(attrs={'class' : 'form-control'}),
'git_link' : forms.URLInput(attrs={'class' : 'form-control'}),
'linkedin_link' : forms.URLInput(attrs={'class' : 'form-control'}),
}
我的觀點,以節省/顯示的是:
student = Student.objects.get(user=request.user)
form = StudentForm(instance=student)
if request.method == 'POST':
form = StudentForm(request.POST, request.FILES, instance=student)
if form.is_valid():
form.save()
messages.success(request, 'Profile successfully updated.')
variables['form'] = form
return render (request, 'app/profile.html', variables)
而且我通過像HTML渲染它這個:
<form method='post' action="{% url 'add-profile' %}" enctype="multipart/form-data" data-confirm="Please confirm you want to save the current data. This will overright all previous data.">
{% csrf_token %}
<table class="table">
{{form.as_table}}
</table>
<button type="submit" class="btn btn-primary" >Update Profile</button>
</form>
我的問題是,爲什麼窗體顯示沒有文件選擇對文件字段甚至當一個文件被加載(以及如何糾正這一點)?
感謝您的幫助