我有一个Python Web应用程序,我想定义一个通用的类或函数来处理网页,并从特定的页面实例的更具体的类中调用它。调用另一个类的类方法导致元类冲突
错误:
metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
我已经检查了所有的StackOverflow问题&回答了有关该错误信息,不明白的解释给(我发现有关我不理解元类的文章 - OOP并不是我的东西)。我也查看了关于从另一个类调用类方法的所有StackOverflow问题&(并且也不理解它们)。
代码:
import webapp2
from datetime import datetime, timedelta
from google.appengine.ext import ndb
from google.appengine.api import users
import admin_templates
import authenticate
class myPage(webapp2.RequestHandler):
def get(pageInstance):
pageInstance.outputHtml()
def outputHtml(pageInstance,pageTitle,pageContent):
adminLink = authenticate.get_adminlink()
authMessage = authenticate.get_authmessage()
adminNav = authenticate.get_adminnav()
pageInstance.response.headers['Content-Type'] = 'text/html'
html = admin_templates.base
html = html.replace('#title#', pageTitle)
html = html.replace('#authmessage#', authMessage)
html = html.replace('#adminlink#', adminLink)
html = html.replace('#adminnav#', adminNav)
html = html.replace('#content#', pageContent)
pageInstance.response.out.write(html)
pageInstance.response.out.write(admin_templates.footer)
class AuditorsPage(webapp2.RequestHandler, myPage.outputHtml):
def get(self):
self.output_auditors()
def output_auditors(self):
self.outputHtml(admin_templates.auditors_title, admin_templates.auditors_content)
如何调用outputHtml
方法从AuditorsPage
类myPage
类没有得到一个元类错误?
为什么'AuditorsPage'尝试从'myPage'的*方法*继承? – chepner
没有特别的理由!只是我无能为力! –
感谢编辑@bruntime,这是一个进步 –