0

I have little problem, I tryed make video uploader but something go wrong models.py

class Video(models.Model): name= models.CharField(max_length=500) videofile= models.FileField(upload_to='videos/', null=True, verbose_name="") def __str__(self): return self.name + ": " + str(self.videofile) 

Forms.py

from django import forms class VideoForm(forms.ModelForm): class Meta: model=Video fields=["name", "videofile"] 

views.py

from django.shortcuts import render from .models import Video from .forms import VideoForm def showvideo(request): lastvideo= Video.objects.last() videofile= lastvideo.videofile form= VideoForm(request.POST or None, request.FILES or None) if form.is_valid(): form.save() context= {'videofile': videofile, 'form': form } return render(request, 'Blog/videos.html', context) 

And yes I made migrations but he telling me that name 'Video' is not defined

1
  • In your forms you did not import the Video model. Commented Jan 19, 2019 at 12:10

1 Answer 1

2

In your forms.py, you specify model = Video, but you forgot to import the Video class, hence in that file, the name Video is not defined.

You can import this like:

# forms.py from django import forms from .models import Video class VideoForm(forms.ModelForm): class Meta: model = Video fields = ["name", "videofile"]

Note that in your view, you should not write form= VideoForm(request.POST or None, request.FILES or None), since then the form becomes invalid if there are simply nor request.POST parameters. You should pass request.POST itself, not request.POST or None.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.