【发布时间】:2017-02-19 01:09:44
【问题描述】:
我正在尝试解决我的一个 Django 应用程序管理员遇到的一个问题。
我有这个代码:
admin_main.py:
application = webapp.WSGIApplication([
# Admin pages
(r'^(/admin/add_img)', admin.views.AddImage),
(r'^(/admin)(.*)$', admin.Admin),])
管理员/views.py:
class BaseRequestHandler(webapp.RequestHandler):
def handle_exception(self, exception, debug_mode):
logging.warning("Exception catched: %r" % exception)
if isinstance(exception, Http404) or isinstance(exception, Http500):
self.error(exception.code)
path = os.path.join(ADMIN_TEMPLATE_DIR, str(exception.code) + ".html")
self.response.out.write(template.render(path, {'errorpage': True}))
else:
super(BaseRequestHandler, self).handle_exception(exception, debug_mode)
class Admin(BaseRequestHandler):
def __init__(self, request,response):
logging.info("NEW Admin object created")
super(Admin, request, response).__init__()
# Define and compile regexps for Admin site URL scheme.
# Every URL will be mapped to appropriate method of this
# class that handles all requests of particular HTTP message
# type (GET or POST).
self.getRegexps = [
[r'^/?$', self.index_get],
[r'^/([^/]+)/list/$', self.list_get],
[r'^/([^/]+)/new/$', self.new_get],
[r'^/([^/]+)/edit/([^/]+)/$', self.edit_get],
[r'^/([^/]+)/delete/([^/]+)/$', self.delete_get],
[r'^/([^/]+)/get_blob_contents/([^/]+)/([^/]+)/$', self.get_blob_contents],
]
self.postRegexps = [
[r'^/([^/]+)/new/$', self.new_post],
[r'^/([^/]+)/edit/([^/]+)/$', self.edit_post],
]
self._compileRegexps(self.getRegexps)
self._compileRegexps(self.postRegexps)
# Store ordered list of registered data models.
self.models = model_register._modelRegister.keys()
self.models.sort()
# This variable is set by get and port methods and used later
# for constructing new admin urls.
self.urlPrefix = ''
def index_get(self):
"""Show admin start page
"""
path = os.path.join(ADMIN_TEMPLATE_DIR, 'index.html')
self.response.out.write(template.render(path, {
'models': self.models,
'urlPrefix': self.urlPrefix,
}))
当我尝试获取页面 http://localhost:8080/admin 时,我收到下一个错误:
ERROR 2016-10-10 14:37:25,484 webapp2.py:1528] __init__() takes exactly 1 argument (3 given)
Traceback (most recent call last):
File "C:\Users\Yisus-MSI\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\webapp2-2.3\webapp2.py", line 1511, in __call__
rv = self.handle_exception(request, response, e)
File "C:\Users\Yisus-MSI\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\webapp2-2.3\webapp2.py", line 1505, in __call__
rv = self.router.dispatch(request, response)
File "C:\Users\Yisus-MSI\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\webapp2-2.3\webapp2.py", line 1253, in default_dispatcher
return route.handler_adapter(request, response)
File "C:\Users\Yisus-MSI\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\webapp2-2.3\webapp2.py", line 1076, in __call__
handler = self.handler(request, response)
TypeError: __init__() takes exactly 1 argument (3 given)
我尝试了很多论坛的解决方案,但没有一个有效。
感谢您的帮助。
【问题讨论】:
-
这似乎根本没有使用 Django。
-
也许这不是 Django 的问题,但我不知道是什么问题@DanielRoseman
标签: python python-2.7 google-app-engine webapp2