장고 - 피스톤을 처음 실행하는 장고 응용 프로그램이 있습니다.django-piston : 클라이언트 응용 프로그램에서 POST 데이터의 형식을 올바르게 지정하십시오.
모델 용으로 구성된 처리기가 있는데 GET 및 POST 용으로 조작되었습니다.
잘 작동합니다. 노력과 진실.
그러나 POST는 빨기입니다. 나는 그것을에 데이터를 게시 할 때, 나는 정말 파이썬에서 프로 아니에요이 오류
Responded: Piston/0.2.3rc1 (Django 1.2.4) crash report:
Method signature does not match.
Resource does not expect any parameters.
Exception was: cannot concatenate 'str' and 'dict' objects
을 얻고 있지만, 몇 가지 기본적인 인터넷 검색이 가이
그래서 오히려 일반적인 파이썬 형식 오류 것 같다 밝혀 여기에 몇 가지 코드가 있습니다.
urls.py (관련 부분)
auth = DjangoAuthentication()
ad = { 'authentication': auth }
word_handler = Resource(handler = WordHandler, **ad)
urlpatterns = patterns(
url(r'^word/(?P<word_id>[^/]+)/', word_handler),
url(r'^words/', word_handler),
)
handlers.py (관련 부분)
class WordHandler(BaseHandler):
allowed_methods = ('GET','POST',)
model = Word
fields = ('string', 'id', 'sort_order', ('owner', ('id',)),)
def read(self, request, word_id = None):
"""
Read code goes here
"""
def create(self, request):
if request.content_type:
data = request.data
print("Words Data: " + data)
existing_words = Word.objects.filter(owner = request.user)
for word in data['words']:
word_already_exists = False
for existing_word in existing_words:
if word["string"] == existing_word.string:
word_already_exists = True
break
if not word_already_exists:
Word(string = word["string"], owner = request.user).save()
return rc.CREATED
는 기본적으로도 전혀, 또는에서()을 만들 점점 아니에요 적어도 그렇게하지 않는 것 같습니다. 앞에서 말한 오류가 발생하여 데이터 수신 방법을 알 수 없습니다.
그리고 단지 그것의 지옥에 대한
, 여기에 내가 매우 도움이 될 것{"words":[{"owner":{"id":1,"tags":null,"password":null,"words":null,"email":null,"firstname":null,"lastname":null,"username":null},"id":1,"sort_order":0,"tags":null,"string":"Another Test"},{"owner":{"id":1,"tags":null,"password":null,"words":null,"email":null,"firstname":null,"lastname":null,"username":null},"id":2,"sort_order":0,"tags":null,"string":"Here's a test"},{"owner":null,"id":0,"sort_order":0,"tags":null,"string":"Tampa"}]}
모든 모든 정보를 게시하려고 데이터입니다.