django-piston に別のハンドラーを実装すると、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)
本当に必要です...
誰かが私のケースを解決するのを手伝ってくれますか?
前もって感謝します