1
我在使用django的Google應用引擎上獲得了一個簡單的應用,而且我有兩個看起來幾乎完全相同的類,但其中一個類與TypeError崩潰。Google應用引擎TypeError問題
Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 3211, in _HandleRequest
self._Dispatch(dispatcher, self.rfile, outfile, env_dict)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 3154, in _Dispatch
base_env_dict=env_dict)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 527, in Dispatch
base_env_dict=base_env_dict)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2404, in Dispatch
self._module_dict)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2314, in ExecuteCGI
reset_modules = exec_script(handler_path, cgi_path, hook)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2212, in ExecuteOrImportScript
script_module.main()
File "C:\Development\fuluus\momadthenomad\main.py", line 20, in main
run_wsgi_app(application)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\webapp\util.py", line 97, in run_wsgi_app
run_bare_wsgi_app(add_wsgi_middleware(application))
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\webapp\util.py", line 115, in run_bare_wsgi_app
result = application(env, _start_response)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\webapp\__init__.py", line 500, in __call__
handler = handler_class()
TypeError: NotFoundPage() takes exactly 1 argument (0 given)
我的類看起來像這樣(main.py):
import os
import datetime
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp.util import run_wsgi_app
class BasePage(webapp.RequestHandler):
def initialize(self, request, response):
webapp.RequestHandler.initialize(self, request, response)
dir = os.path.join(os.path.dirname(__file__), "../templates")
self.template_path = os.path.abspath(dir)
def render_to_response(self, page, template_values):
page_path = os.path.join(self.template_path, page)
self.response.out.write(template.render(page_path, template_values))
class DefaultPage(BasePage):
def get(self):
visitor = Visitor()
visitor.ip = self.request.remote_addr
visitor.put()
page = Page()
page.title = "MY PORTAL"
page.subtitle = "Home"
page.name = self.request.path
visitors_query = Visitor.all().order('-added_on')
visitors = visitors_query.fetch(20)
self.render_to_response("main.html",
{
"page": page,
"visitors": visitors,
})
def NotFoundPage(BasePage):
def get(self):
page = Page()
page.title = "MY PORTAL"
page.subtitle = "Not Found"
page.name = self.request.path
self.render_to_response("empty.html",
{
"page": page,
})
application = webapp.WSGIApplication(
[('/', DefaultPage),
('/index.html', DefaultPage),
('/.*', NotFoundPage),
],
debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
當我去/index.html,一切都很完美。但是當我轉到/not-found.html時,它會因錯誤而崩潰。我無法弄清楚這個腳本有什麼問題。也許我忽略了一些東西。請幫忙。
你值得+1 :) – Tauquir 2010-11-20 21:45:23
OMG感謝福氣! – 2010-11-20 23:09:01