Trac AttributeError:尝试在系统中获取组件时,'str'对象没有属性'db_query'错误

时间:2014-01-29 15:13:31

标签: python trac

我正在尝试获取当前环境中的所有组件,但我无法理解的原因是我收到以下错误:

AttributeError: 'str' object has no attribute 'db_query'

这是代码(跳过某些部分):

  from trac.core import *
  from trac.ticket import model

  class TracIteraDirectory(Component):

  implements(INavigationContributor, ITemplateProvider, IRequestHandler)

  def process_request(self, req):
       myenv = '/home/konart/backup/Trac/TracDB/Planing'
       self.db = self.env.get_db_cnx()

       components = []
       test = model.Component(myenv)
       test1 = test.select(myenv)

       for each in test1:
           components.append((each.name, each.owner))

       #for component in model.Component(myenv).select(myenv):
           #components.append((component.name, component.owner))

我已经在trac-hacks.org和核心文件上查看了一些插件exanples,但是我无法理解我在这里做错了什么(或根本没有做错)

1 个答案:

答案 0 :(得分:1)

我想我过度劳累了一下。 答案很简单 - 我传递了一个带有路径的简单字符串到我的env,而不是传递一个实际的Environment对象:

def process_request(self, req):

    if req.path_info.startswith('/traciteradirectory'):

        components = []
        test = model.Component(self.env)
        test1 = test.select(self.env)