私はPython Webアプリケーションを持っているので、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のすべての質問&は、別のクラスからのクラスメソッドを呼び出す(それらを理解していない)についての答えを見た。
コード:私はメタクラスのエラーを取得せずにAuditorsPage
クラスからmyPage
クラスのoutputHtml
メソッドを呼び出すにはどうすればよい
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)
?
なぜ 'AuditorsPage'は' myPage'の*メソッド*から継承しようとしていますか? – chepner
特別な理由はありません!ただ私は不適格! –
編集に感謝します。 –