django


Django form shows No File Chosen


My question is, why does the form show No File Chosen against the file fields even when a file is loaded (and how do I correct this)?
I have the following form (the relevant bits being the FileInput widgets):
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'}),
}
My view to save/display for is :
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)
And I am rendering it through HTML like this:
<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>
My question is, why does the form show No File Chosen against the file fields even when a file is loaded (and how do I correct this)?
Thanks for your help
My solution (which I don't like) has been to use {{form.field}} and for the URL fields include {{form.field.url}}. I can then apply CSS formatting to remove the standard button and apply my own without the No File Chosen text.
Horrid

Related Links

Django Channels message life time
Django REST Framework viewset doesn't obey pagination_class
DRF Serializer Field return value different from value saved to database
Django - Create Custom Database Type
Django - static/CACHE files not found
Any atomic way in Django to force Postgres's AutoField sequence to be updated on explicit insertions?
How to count executed queries during selenium test?
django registering models with many-to-many circular reference on Admin
Django conditional require for an entire form
Error when creating a new user from a template in django
Django migration default value callable generates identical entry
django adding admin category error
Filtering prefetch_related() to optimize data set
InconsistentMigrationHistory with django user_auth
Bitnami Django Stack 500 Internal Server Error
django rest framework : nested model get not working. 'str' object has no attribute 'values'

Categories

HOME
algorithm
azure-stream-analytics
c99
mjml
interface
bitbucket-api
edge
switch-statement
rds
jquery-ui-sortable
frequency-distribution
linear-algebra
connector
sar
roslyn
object-storage
monit
comparator
strongname
draft-js-plugins
surveymonkey
soot
exchangewebservices
paperjs
mustache
left-join
dsx-desktop
sendbird
fossil
hibernate-search
apache-stanbol
trigonometry
sharp-snmp
show-hide
snapchat
httrack
automapper-5
gitlist
yii2-user
check-mk
lsyncd
gpg-signature
filenet
sandcastle
cvxpy
materialized-path-pattern
cubism.js
uicolor
macaulay2
simevents
android-wake-lock
tracker-enabled-dbcontext
cda
redis-cluster
yajsw
html-to-pdf
nullable
pushbots
tfs-workitem
gocql
wiredep
slash
ocra
airbrake
cwrsync
apache-spark-1.3
webmatrix-3
crowd
post-commit-hook
sql-scripts
cocos3d
encryption-asymmetric
build-script
verold
codeplex
terminate
cfcache
windows-embedded-standard
rfc5322
gtm-oauth2
solace-mq
ice-cube
ebay-lms
rolify
beaker-testing
cmmi
device-width
joomla3.1
midlet
faye
apache-whirr
azman
screen-size
tmx
timertask
cruisecontrol.rb

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile