来自继承类的访问请求(视图)

时间:2014-12-31 09:34:52

标签: python django inheritance request

如果我没有从继承类(视图)实现get / post方法,我如何访问var请求?

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']

如果某些视图继承自Base会发生什么?像这样。

class login(Base):

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

错误是:'登录'对象没有属性'请求'

很多。

1 个答案:

答案 0 :(得分:1)

request对象可用作View实例的属性:

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