title: Django - Have function inside of a view function automatically return a response to user if error?
body: <p>So I have this post request below that gets a video upload then validates it. I'd ideally like <code>validate_video_upload()</code> to return a <code>400</code> response if the video is larger than the allowed size rather than raise a validation error, because I'd like to notify the user that the video is too large. How do I set it up so that if <code>validate_video_upload()</code> returns a Response, it'll just return the call with the status and message, if there's no response returned then it just proceeds normally?</p>
  <p>View.py</p>
  <pre><code>def post(self, request):
      if 'video' in request.FILES.keys():
          vid = request.FILES.get('video')
          validate_video_upload(vid)
  </code></pre>
  <p>function.py</p>
  <pre><code>def validate_video_upload(file):
      if not is_valid_file_of_format(file._name, VALID_VIDEO_EXTENSIONS):
          raise ValidationError(&quot;Video file format is invalid&quot;)
      if file.size&gt;2296000000:
          raise ValidationError(&quot;Maximum size allowed for a video is 287 mb&quot;)
  </code></pre>