0

kindly help me, i am using class based views now am about to create new post using Createview i added all the fields including an image which stands for the thumbnail so if i go to http://127.0.0.1:8000/pages/blog/new/ i get a form and if i fill in the fields and submit i get return back to the form saying the image fields is required meanwhile i already inserted an image , this is the error in picture and this is my code below

views.py

class BlogCreateView(LoginRequiredMixin, CreateView):
    model = Blog
    fields = ['title', 'categories', 'overview', 'thumbnail', 'summary']

blog_form.html

<div class="content-section text-center">
     <form method="POST">
         {% csrf_token %}
         <fieldset class="form-group ">
             <legend class="border-bottom mb-4 h2">Blog Post</legend>
             {{ form|crispy }}
         </fieldset>
         <div class="form-group">
             <button class="btn btn-outline-info" type="submit">Post</button>

         </div>
     </form>
</div>
Exactman
  • 43
  • 8

1 Answers1

1

You need to add "enctype="multipart/form-data" to your form, so:

<form method="post" enctype="multipart/form-data">

See detailed explanation is this elaborate answer: What does enctype='multipart/form-data' mean?

FSE
  • 36
  • 3