1
我在我的django項目中遇到了一個錯誤,當我爲我的Django活塞實現另一個處理程序時。Django活塞處理程序錯誤
Request Method: GET
Request URL: http://127.0.0.1:8000/api/getdata/
Django Version: 1.3.1
Python Version: 2.7.1
Installed Applications:
['admin_tools.theming',
'admin_tools.menu',
'admin_tools.dashboard',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'app',
'api',
'south']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.csrf.CsrfResponseMiddleware')
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
101. request.path_info)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
252. sub_match = pattern.resolve(new_path)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
250. for pattern in self.url_patterns:
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in _get_url_patterns
279. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in _get_urlconf_module
274. self._urlconf_module = import_module(self.urlconf_name)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module
35. __import__(name)
File "/home/agileone/workspace/proj/api/urls.py" in <module>
15. devdata_handler = Resource(DevDataHandler)
File "/usr/local/lib/python2.7/dist-packages/django_piston-0.3dev-py2.7.egg/piston/resource.py" in __init__
36. self.handler = handler()
Exception Type: TypeError at /api/getdata/
Exception Value: DevDataHandler() takes exactly 1 argument (0 given)
我不知道我爲什麼得到這些的原因是什麼。
這是我api/urls.py
from django.conf.urls.defaults import *
from piston.resource import Resource
from api.handlers import *
from django.http import HttpResponse
from piston.handler import BaseHandler, AnonymousBaseHandler
class CsrfExemptResource(Resource):
def __init__(self, handler, authentication=None):
super(CsrfExemptResource,self).__init__(handler,authentication)
self.csrf_exempt=getattr(self.handler,'csrf_exempt',True)
data_handler = CsrfExemptResource(DataHandler)
devdata_handler = Resource(DevDataHandler)
urlpatterns=patterns('',
url(r'^getdata/$', data_handler, {'emitter_format': 'ext-json'}),
url(r'^getdevdata/$', devdata_handler, {'emitter_format': 'ext-json'})
)
,這是我api/handlers.py
from django.utils import simplejson
from piston.handler import BaseHandler, AnonymousBaseHandler
from app.models import *
from django.db.models import *
from piston.utils import rc, require_mime, require_extended, validate
import datetime
class DataHandler(BaseHandler):
allowed_method = ('GET', 'POST', 'PUT', 'DELETE')
fields = ('title')
model = Data
def read(self, request):
data = {"msg":"Hello world"}
return data
def DevDataHandler(BaseHandler):
allowed_method = ('GET', 'POST', 'PUT', 'DELETE')
fields = ('title')
model = Data
def read(self, request):
data = {"msg":"Hi world"}
return data
,如果我不包括devdata_handler = Resource(DevDataHandler)
但我真的需要它,它的工作原理...
做任何人可以幫助我解決我的情況?
在此先感謝
我沒有看到任何明顯的代碼。但只是開始,你不應該創建綁定到相同模型的兩個處理程序 – jdi