Why this error showing while created a form to upload image in Django

Error raised is here

enter code here

This is the view to addpost and inherited from CreateView. views.py

class PostAddView(CreateView):
    template_name="add_post.html"
    form_class=PostForm
    model=AddPost
    success_url=reverse_lazy("index")
    context_object_name="posts"

models.py

class AddPost(models.Model):
    post=models.ImageField(upload_to="postimages",null=True)
    caption=models.CharField(max_length=200)
    user=models.ForeignKey(MyUser,on_delete=models.CASCADE)
    created_date=models.DateTimeField(auto_now_add=True)

Here MyUser is a abstract user

forms.py

class PostForm(forms.ModelForm):
    class Meta:
        model=AddPost
        fields=["post","caption"]
    
        widget={
            "post":forms.FileInput(attrs={"class":"form-control"}),
            "caption":forms.Textarea(attrs={"class":"form-control","rows":3})
        }

template given to render the form. (add_post.html)

<!DOCTYPE HTML>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div class="container">
        <div class="row">
            <div class="col-2"></div>
            <div class="col-3">
                <form action="" method="post" enctype="multipart/form-data">
                    {%csrf_token%}
                    {{form.as_p}}
                    <input type="submit" value="Post">
                 </form>
            </div>
            <div class="col-2"></div>   
          </div>
     </div>
</body>
</html>
Back to Top