File not getting uploaded

53 views
Skip to first unread message

Aakash Baranwal

unread,
Apr 17, 2019, 2:35:56 AM4/17/19
to django...@googlegroups.com
Hi Everybody,

I am trying to upload a file, but it says "No file chosen", even when I have selected the file. However it is getting uploaded when I have logged in as as admin and i am uploading it from there.

Kindly help me, thanks in advance.

views.py file:

class VideoCreateView(CreateView):
form_class = VideoModelForm
fields = ['Video_Description','videofile']
template_name = 'deploy/create_view.html'

success_url = "/video/create/"

def form_valid(self, form):
form.instance.user = self.request.videofile
return super(VideoCreateView, self).form_valid(form)


models.py file:

class Video(models.Model):
    Video_Description= models.CharField(max_length=500)
    videofile= models.FileField(upload_to='videos/', null=True, verbose_name="")
    timestamp   = models.DateTimeField(auto_now_add=True)

    class Meta:
    ordering = ['-timestamp']


    def __str__(self):
        return self.Video_Description + ": " + str(self.id)


urls.py file:


url(r'^create/$', VideoCreateView.as_view(), name='create')


create_view.html :

<form class='form' method="POST" action="">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Upload" / >
</form>

PFA the image file displaying the page after i selected the file and hit the Upload Video button

With Kind Regards

Aakash Baranwal

Aakash Baranwal

unread,
Apr 17, 2019, 2:36:41 AM4/17/19
to django...@googlegroups.com
Sorry, the image file wasnt uploaded.


Screenshot (2).png

Vijay Khemlani

unread,
Apr 17, 2019, 8:49:00 AM4/17/19
to django...@googlegroups.com
In your HTML, the form tag should have an enctype

<form ... enctype="multipart/form-data">
...
</form>

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALr9hQ2eq0np-THVoQOBJ6ux3fqw%2BzA1DM4DBHshTP5dMNat2g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Ram sundar

unread,
Apr 17, 2019, 9:53:26 AM4/17/19
to django...@googlegroups.com
Hi Vijay,

You are right, but he has mentioned that it gets uploaded when logged in as admin. Will it be a different template for the same view? Just wondering... 

@Aakaash: can you please check in both cases and confirm please

Regards, 
Ramsundar


Vijay Khemlani

unread,
Apr 17, 2019, 10:07:25 AM4/17/19
to django...@googlegroups.com
When he said "uploading it from there" I was not sure whether "there" meant Django's admin page or the same view that's failing now

As far as I know the form has to have a multipart enctype to upload files

Aakash Baranwal

unread,
Apr 17, 2019, 2:10:19 PM4/17/19
to django...@googlegroups.com
Hi,

Actually, his solution was correct because when I provided the encryption it worked, however I am not sure about the reason why it did worked at all.

Thanks a lot.

With Kind Regards
Aakash Baranwal
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Aakash Baranwal

unread,
Apr 17, 2019, 2:10:54 PM4/17/19
to django...@googlegroups.com
Thanks a lot. Your solution worked perfectly for me. 

With Kind Regards
Aakash Baranwal
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

adarsh pandey

unread,
Apr 18, 2019, 11:16:39 AM4/18/19
to django...@googlegroups.com
Gentle man you have not given enctype=" form/multipartdata" in the form tag of the HTML file


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Aakash Baranwal

unread,
Apr 18, 2019, 12:04:59 PM4/18/19
to django...@googlegroups.com
Yes Sir,

I corrected it. Thanks a lot.

Best 
Aakash

Reply all
Reply to author
Forward
0 new messages