1๐
You have to include {{form.media}} to the django form template if you want to post any type of media to django
<form method="POST" enctype="multipart/form-
data>
{% csrf_token %}
{{form.media}}
<input type="file" class="form-control"
idd="customFile" name="image"/></div>
<input type="text" class="form-control"
name="name" placeholder="">
</div>
</form>
edit:
and in views.py you have to use request.FILES to get any media file(forgot to mention this)
request.FILES.get('image')
and to get the image from media use .url
{% Profileobject.image.url %}
๐คPinjarla Girish
0๐
Uploaded files are in request.FILES
instead of request.POST
. So your file handling should look like this:
# post.image= request.POST.get('image')
post.image = request.FILES['image']
Iโd recommend to read the Django docs about file uploads
๐คyedpodtrzitko
0๐
use request.FILES
:
def hotel:
if request.method == "POST" :
post=Profile()
post.image= request.FILES['image']
post.name = request.POST.get('name')
post.save()
return redirect('/vendor_dashboard/profile_pic')
return render(request,'profile.html')
๐คhakim13or
- [Answered ]-Virtualenv wont work on
- [Answered ]-Does acccessing nested FK relation's field value downgrade performance?
- [Answered ]-Conflict in django models . How to debug?
- [Answered ]-How can I reliably launch multiple DJango FCGI servers at startup?
Source:stackexchange.com