[Answered ]-Uploading image is not creating media file

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

Leave a comment