8
you should use in template where you are uploading form:
<form class="form-horizontal form_middle" enctype='multipart/form-data' method="POST">
#apply logic for media upload
</form>
2
in views.y, the form you are saving should also have request.FILES
studentProfileForm = StudentRegisterForm(request.POST, request.FILES)
if studentProfileForm.is_valid():
user = studentProfileForm.save()
- [Django]-How to use FilePond in Django project
- [Django]-Force re-collectstatic with django static?
- [Django]-Type object is not iterable Django
- [Django]-How do I programmatically create a user with django_social_auth?
-1
File upload is a bit weird in model forms in django.
Change your forms.py to –
class APostForm(forms.ModelForm):
photo=forms.FileField(label='Upload image') # or image field
class Meta:
model = Post
fields = {'title','content'}
form.save() will automatically save the field.
- [Django]-How to manually build a django `HttpRequest`
- [Django]-Django admin datetime widget (calendar) in a custom form
- [Django]-Cannot Connect to Django from outside the Local Server
- [Django]-Django Haystack + Elasticsearch strange intermittent bug
Source:stackexchange.com