title: Error Showing whenever I try to post without img Django
body: <p>I'm trying to create a social media but whenever I try to post some post without an image field it's throwing me an Error saying &quot;<strong>The 'post_img' attribute has no file associated with it.</strong>&quot;. It works fine when I post something with the image but I want it to be like Twitter where you can post a blog and Image. So I don't know what's going on.</p>
  <p><a href="https://i.stack.imgur.com/buHRy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/buHRy.png" alt="enter image description here" /></a></p>
  <p>Models.py</p>
  <pre><code>from django.db import models
  from django.utils import timezone
  from django.contrib.auth import get_user_model
  User = get_user_model()
  from PIL import Image
  
  # Create your models here.
  class PostTag(models.Model):
      tag = models.CharField(max_length=10)
  
      def __str__(self):
          return self.tag
  
  class Post(models.Model):
      title = models.CharField(max_length=200)
      content = models.TextField(null = True, blank=True)
      post_img = models.ImageField(upload_to = &quot;posts_img&quot;, null = True, blank = True)
      pub_date = models.DateTimeField(default = timezone.now)
      post_tag = models.ForeignKey(PostTag, on_delete=models.SET_NULL, null= True,blank=True) 
      author = models.ForeignKey(User, on_delete= models.CASCADE)
      
      def __str__(self):
          return f&quot;{self.title} / {self.author}&quot;
      if post_img:
          def save(self,*args, **kwargs):
              super().save(*args, **kwargs)
  
              img = Image.open(self.post_img.path)
  
              if img.height &gt; 600 or img.width &gt; 600:
                  output_size = (600, 600)
                  img.thumbnail(output_size)
                  img.save(self.post_img.path)
  </code></pre>
  <p>views.py</p>
  <pre><code>from django.shortcuts import render,redirect
  from django.contrib.auth.decorators import login_required
  from .forms import PostCreateForm
  from django.contrib import messages
  # Create your views here.
  @login_required(login_url=&quot;users:index&quot;)
  def posts_view(request):
      form = PostCreateForm(request.POST or None, request.FILES or None)
      if form.is_valid():
          obj = form.save(commit=False)
          obj.author = request.user
          obj.save()
          messages.success(request, &quot;Successfully Posted your Post&quot;)
          return redirect(&quot;posts:posts_view&quot;)
      else:
          form = PostCreateForm()
      context = {
          &quot;form&quot;: form
      }
      return render(request, &quot;posts.html&quot;, context)
  </code></pre>