2016-10-10 57 views
0

我試圖解決一個問題,我有我的管理一個Django應用程序。錯誤__init __()只需要1個參數(3給出)在DjEngo與GAE

我有這樣的代碼:

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) 

我嘗試了很多論壇的解決方案,但沒有人工作。

感謝您的幫助。

+0

這似乎並沒有被使用Django的。 –

+0

也許它不是Django的問題,但我不知道是什麼問題@DanielRoseman – Yisus

回答

0

我相信你在使用super()犯了一個錯誤,你需要在你Admin.__init__()方法來改變:

super(Admin, request, response).__init__() 

到:

super(Admin, self).__init__(request=request, response=response) 
相關問題