title: Django Attribute Error: 'NoneType' object has no attribute 'videofile'
body: <p>I am following <a href="http://www.learningaboutelectronics.com/Articles/How-to-create-a-video-uploader-with-Python-in-Django.php" rel="nofollow noreferrer">this</a> tutorial to create a video uploader in my Django project and have run into this error:</p>
  
  <p>..src/video/views.py", line 9, in showvideo
      videofile= lastvideo.videofile
  AttributeError: 'NoneType' object has no attribute 'videofile'</p>
  
  <p>I'm sure I am missing something obvious and have been looking for the answer for a while now. Would be grateful for any help.</p>
  
  <pre><code>views.py
  
  from django.shortcuts import render
  from .models import VideoUpload
  from .forms import VideoForm
  
  def showvideo(request):
  
      lastvideo= VideoUpload.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, 'video.html', context)
  </code></pre>
  
  <pre><code>forms.py
  
  from django import forms
  from .models import VideoUpload
  
  
  class VideoForm(forms.ModelForm):
  
      class Meta:
          model = VideoUpload
          fields = ["name", "videofile"]
  </code></pre>
  
  <pre><code>models.py
  
  from django.db import models
  
  class VideoUpload(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)
  </code></pre>
  
  <pre><code>from django.conf import settings 
  from django.contrib import admin
  from django.urls import path
  from django.conf.urls.static import static
  
  from video.views import (
      showvideo,
  )
  
  urlpatterns = [
      path('showvideo', showvideo, name='showvideo'),
  ]
  
  if settings.DEBUG:
   urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
   urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
  </code></pre>
  
  <p>FYI I updated the name of the model to 'VideoUpload' vs the tutorial.</p>