user3612445
user3612445

Reputation: 145

Access request from inherit class ( view )

How can I acces the var request if I not implement the methods get/post from a inherit class( view ) ?

class Base(View): 
    def __init__(self):
          self.menu="options": [
            {
                "link": "home:IndexHome",
                "name": "Base",
                "class": "icon-dashboard",
                "section" : "home",

            },
            {
                "link": "reports:IndexReports",
                "name": "Informes",
                "class": "icon-list-alt",
                "section":"reports",
            }]}
   def somemethod(self):
           request.session['idsession']

And what happens if some view inherit from Base? Like this.

class login(Base):

def __init__(self):
    Base.__init__(self)

The error is : 'login' object has no attribute 'request'

Thx a lot.

Upvotes: 0

Views: 189

Answers (1)

catavaran
catavaran

Reputation: 45575

request object is available as a property of a View instance:

def somemethod(self):
    self.request.session['idsession']

Upvotes: 1

Related Questions