ListView can not return to other page. NameError

49 views Asked by At

I have made ListView, it has "Try and Except block"

When it passes try block, it shows listview with SQL data. but when it does not, I want to let the user go to another page (cancel.html).

Here is my code.

view.py

class DbList(ListView):
   
    def get(self, request):

        try:
            stripe_customer = StripeCustomer.objects.get(user=self.request.user)
            stripe.api_key = settings.STRIPE_SECRET_KEY
            subscription = stripe.Subscription.retrieve(stripe_customer.stripeSubscriptionId)
            print(subscription.status)    

            if subscription.status == "active":

                sql = 'select * from test_eu'
                msg = "abcdefg"
                sql += " where eng_discription ~ '.*" + msg +".*' ORDER BY image_amount DESC " 
                object_list = TestEu.objects.raw(sql)
                return object_list

        except:
            return render(request, 'cancel.html')

The error message is

NameError name 'request' is not defined

So I tried to change the code

return render(request, 'cancel.html')

to

return render(self.request, 'cancel.html')

Then another error message occurred.

TypeError object of type 'HttpResponse' has no len()

How can I let the user go to another page in Listview??

I just mentioned the above settings in this question but still if more code is required then tell me I'll update my question with that information.

0

There are 0 answers