0

My Form Image

I am working on an upload post page which includes images. When I am on the update page I want my previously uploaded photo to be chosen already in the file-upload field.

I am doing this in my html file but it is not working

<div class="qq-uploader-buttonText-value">
    <input type="file" id="input_22" name="photo1" class="form-control-file" data-imagevalidate="yes" data-file-accept="pdf, doc, docx, xls, xlsx, csv, txt, rtf, html, zip, mp3, wma, mpg, flv, avi, jpg, jpeg, png, gif" data-file-maxsize="10854" data-file-minsize="0" data-file-limit="" value="{{Post.photo1.url}}" data-component="fileupload" />
</div>

views.py

import random
from django.shortcuts import redirect, render
from django.http import HttpResponse

from home.models import Posts

@login_required(login_url='login')
def update(request, posts_id):
     Post = Posts.objects.get(postid=posts_id)
     context = {'Post':Post,'cod':usrid}

     return render(request, 'update.html', context)

urls.py

from django.contrib.auth import logout
from django.urls import path
from . import views
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    path('update/<str:posts_id>/',views.update,name="update"),
] + static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)

Can anyone help me how I do this?

Damoiskii
  • 1,328
  • 1
  • 5
  • 20
  • It would be good if you re-edit your question and add the `view` that is passing the `object/queryset` with the `photo/photos` you would like to display. – Damoiskii Jun 20 '22 at 20:38
  • @Damoiskii @K J Sorry for not elaborating.... I have edited my question.. Please Check now. – Shahid Fahad Jun 20 '22 at 21:30
  • Why not use Django forms to deal with this? You could pre-populate a Django form from the server-side and this will give you exactly what you need. – Damoiskii Jun 23 '22 at 00:23
  • From client-side, would something like this work for you? https://stackoverflow.com/a/16326195/15978450 – Damoiskii Jun 23 '22 at 00:36

0 Answers0