Error: No file was submitted. Check the encoding type on the form

Please I’m having issue with register vendor, all was working fine before, so I just decided to retest everything have done, to my surprise the code thats working perfectly before is no more working. please help me out guys.............................................................................................................................................................

views.py

def registerRestaurant(request):
    # this restrict user from going to Vendor Registration Page after Logged in 
    if request.user.is_authenticated:
        messages.warning(request, "You are already logged in!")
        return redirect('dashboard')

    if request.method == 'POST':
        form = UserForm(request.POST, request.FILES)
        v_form = vendorForm(request.POST, request.FILES or None)
        if form.is_valid() and v_form.is_valid():
            password = form.cleaned_data['password'] # clean_data will return 'dict value'
            user = form.save(commit=False)
            user.set_password(password)
            user.role = User.VENDOR
            user.save()
            vendor = v_form.save(commit=False)
            vendor.user = user
            user_profile = UserProfile.objects.get(user=user)
            vendor.user_profile = user_profile
            vendor.save()
           
            mail_subject = 'Please Activate your Account'   
            email_template = 'accounts/emails/account_verification_email.html'
            send_verification_email(request, user, mail_subject, email_template)   #send_verification_email is function created in utils.py
            messages.success(request, "Your Account has been Registered Successfully, Please Wait for Approval")
            return redirect('registervendor') 
        else:
            messages.error(request, 'An Error occurred during registration!')
    
    else:
        form = UserForm()
        v_form = vendorForm()
    context = {
        'form': form,
        'v_form': v_form,
    }
    return render(request, 'vendor/registervendor.html', context)

model.py (vendor)

class Vendor(models.Model):
    user = models.OneToOneField(User, related_name='user', on_delete=models.CASCADE)
    user_profile = models.OneToOneField(UserProfile, related_name='userprofile', on_delete=models.CASCADE)
    vendor_name = models.CharField(max_length=50)
    vendor_lincense = models.ImageField(upload_to='vendor/lincense')
    is_approved = models.BooleanField(default=False)
    created_at = models.DateTimeField(auto_now_add=True)
    modified_at = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return self.vendor_name

model.py (UserProfile)

class UserProfile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE, blank=True, null=True)
    profile_picture = models.ImageField(upload_to='users/profile_pictures', blank=True, null=True)
    cover_photo= models.ImageField(upload_to='users/cover_photos', blank=True, null=True)
    address = models.CharField(max_length=250, blank=True, null=True)
    country = models.CharField(max_length=20, blank=True, null=True)
    state= models.CharField(max_length=20, blank=True, null=True)
    city = models.CharField(max_length=20, blank=True, null=True)
    pin_code = models.CharField(max_length=6, blank=True, null=True)
    latitude = models.CharField(max_length=20, blank=True, null=True)
    longitude = models.CharField(max_length=20, blank=True, null=True)
    created_at = models.DateTimeField(auto_now_add=True)
    modified_at = models.DateTimeField(auto_now_add=True)


    # # Concatenate Address 1 and Address 2
    # def full_address(self):
    #     return f'{self.address_line_1}, {self.address_line_2}'
        

    def __str__(self):
        return self.user.email

template

                    <div id="restaurant-sets-holder">
                        <form class="form-fields-set foodbakery-dev-restaurant-form" action = "{% url 'registervendor' %}" method = 'post'  enctype = 'multipart/form-data'>
                            {% csrf_token %}
                            <ul class="register-add-restaurant-tab-container restaurant-information-tab-container">
                                <li>
                                    <div class="row">
                                        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                                            <div class="row">
                                                <ul >
                                                    <li>
                                                        <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
                                                            <div class="field-holder">
                                                                <label>First name</label>{{form.first_name}}
                                                            </div>
                                                        </div>
                                                        <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
                                                            <div class="field-holder">
                                                                <label>Last name</label>{{form.last_name}}
                                                            </div>
                                                        </div>
                                                        <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
                                                            <div class="field-holder">
                                                                <label>Restaurant name</label>{{v_form.vendor_name}}
                                                            </div>
                                                        </div>
                                                        <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
                                                            <div class="field-holder">
                                                                <label>Restaurant lincense</label>{{v_form.vendor_lincense}}
                                                            </div>
                                                        </div>
                                                        
                                                        <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
                                                            <div class="field-holder">
                                                                <label>Email Address</label>{{form.email}}
                                                            </div>
                                                        </div>
                                                        <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
                                                            <div class="field-holder">
                                                                <label>Username</label>{{form.username}}
                                                            </div>
                                                        </div>
                                                    </li>
                                                    
                                                    <li>
                                                        <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
                                                            <div class="field-holder">
                                                                <label>Password</label>
                                                                {{form.password}}
                                                            </div>
                                                        </div>
                                                        <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
                                                            <div class="field-holder">
                                                                <label>Confirm Password</label>
                                                               {{form.confirm_password}}
                                                            </div>
                                                        </div>
                                                    </li>
                                                </ul>
                                            </div>
                                        </div>
                                    </div>
                                </li>
                                <li>
                                    <ul class="errorlist">
                                        
                                        <!-- Fields Error -->
                                        {% for field in form %}
                                            {% if field.errors %}
                                                {% for error in field.errors %}
                                                    <li style="color: red">{{error}}</li>
                                                {% endfor %}
                                            {% endif %}
                                        {% endfor %}

                                        <!-- Non Field Error -->
                                        <li style="color: red">{{form.non_field_errors}}</li>
                                    </ul>
                                    <div class="row">
                                        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                                            <div class="field-holder">
                                                <div class="payment-holder">
                                                    <input type="submit" value="Submit" id="btn-next-restaurant-information" class="bgcolor">
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    
                                    <!-- Success Message Display -->
                                    <div class="row">
                                        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                                            <!-- Load Message -->
                                            {% include 'alerts.html' %}
                                        </div>
                                    </div>

                                </li>
                            </ul>
                        </form>

Back to Top