Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

101
Views
Problem with getting data from input for django

I have a problem with getting data from the tag on the page with the Django form.

templates:

<form method="post" enctype="multipart/form-data">
                {% csrf_token %}
                <input id="result" type="hidden">
                <script type="text/javascript">
                    const upload = document.querySelector('#inputGroupFile01');
                    const result = document.querySelector('#result');

                    upload.addEventListener("change", (e) => {
                        previewFunc(e.target.files[0]);
                    });

                    function previewFunc(file) {
                        if (!file.type.match(/image.*/)) return false;
                        const reader = new FileReader();

                        reader.addEventListener("load", (e) => {
                            const label = document.createElement('label');
                            label.for = 'photo';
                            const input = document.createElement('input');
                            result.name = 'photo';
                            result.value = 'e.target.result';
                            result.src = e.target.result;
                            result.type = 'image';
                            result.id = 'result';
                            {#result.innerHTML = '';#}
                            {#result.append(input);#}
                        });
                        reader.readAsDataURL(file);
                    }
                </script>
                <button type="submit">{% trans 'Apply' %}</button>
            </form>

Views:

class LoadPhotoView(BaseMixin, generic.CreateView):
    model = Photo
    template_name = 'load_photos/load_photo_page.html'
    form_class = PhotoUploader

    def post(self, request, *args, **kwargs):
        print(request.POST.get('photo'))
        print(request.FILES.getlist('photo'))
        print(request.FILES.get('photo'))

        return render(request, self.template_name, {'form': self.form_class})

After executing javascript code page has next structure at the screen: enter image description here

But I still can't get photo in method post in my view(I get None or empty list)

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!