我試圖發送一個Backbone.js的模型作爲POST到活塞和我得到一個錯誤:無法將關鍵字'model'解析爲字段。活塞與Backbone.js的
活塞/ 0.2.2(Django的1.3)崩潰報告:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/piston/handler.py",
line 81, in create inst = self.model.objects.get(**attrs)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/manager.py",
line 132, in get return self.get_query_set().get(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py",
line 341, in get clone = self.filter(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py",
line 550, in filter return self._filter_or_exclude(False, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py",
line 568, in _filter_or_exclude clone.query.add_q(Q(*args, **kwargs))
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/query.py",
line 1172, in add_q can_reuse=used_aliases, force_having=force_having)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/query.py",
line 1060, in add_filter negate=negate, process_extras=process_extras)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/query.py",
line 1238, in setup_joins "Choices are: %s" % (name, ", ".join(names)))
FieldError: Cannot resolve keyword 'model' into field.
Choices are: calendar, date, id, name, priority
代碼:
$(function() {
Backbone.emulateJSON = true;
$('form').submit(function() {
formdict = jsonform($("form#add_task :input"));
var new_task = new Task({
calendar: formdict.calendar,
date: formdict.date,
name: formdict.name,
priority: formdict.priority});
console.log("new _task: " + new_task);
new_task.save();
return false;
});
});
});
響應和請求信息:
Request URL:http://localhost:8000/api/task/
Request Method:POST
Status Code:500 INTERNAL SERVER ERROR
Request Headersview source
Accept:application/json, text/javascript, */*; q=0.01
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:no-cache
Connection:keep-alive
Content-Length:156
Content-Type:application/x-www-form-urlencoded
X-Requested-With:XMLHttpRequest
Form Dataview URL encoded
model:{"date":"2012-03-10T01:12:43.876Z","name":"New event","priority":0,"id":1,"calendar":"null"}
響應頭文查看源代碼
Access-Control-Allow-Headers:Origin,Content-Type,Accept
Access-Control-Allow-Methods:POST,GET,OPTIONS,PUT,DELETE
Access-Control-Allow-Origin:*
Content-Type:text/html; charset=utf-8
Date:Sat, 10 Mar 2012 01:12:44 GMT
Server:WSGIServer/0.1 Python/2.7.2+
Vary:Authorization
如何讓活塞接受模型?
什麼是發送到服務器的請求?這顯然是服務器端錯誤,您能否與我們分享相關部分? – Tadeck 2012-03-10 01:13:04
附加請求。 – user784756 2012-03-10 01:16:19