Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

The view fitness_app.views.BookingView didn't return an HttpResponse object. It returned None instead

I dont understand as this code was working fine earlier and now i am receiving the above error when the form is submited.
views.py file

class BookingView(FormView):
    form_class = AvailabilityForm
    template_name = "availability.html"

    def form_valid(self, form):
        data = form.cleaned_data
        
        bookingList = Appointment.objects.filter()
        for booking in bookingList:
            if booking.start == data["start_time"]:
                print("Cant be booked")
                return HttpResponse("Cant be booked")
            else:
                booking=Appointment.objects.create(
                    name=data["name"], 
                    start=data["start_time"],
                    end=data["end_time"]
                    )
                booking.save()
                return HttpResponse("can be booked")

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

your queryset is empty so your code never reaches the conditions inside the for loop.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading