在django中返回500内部服务器错误

时间:2017-05-15 15:32:56

标签: jquery python ajax django ember.js

我在django中用ajax做一个表单请求,但响应总是500,我没有任何ideia错误。

我的ajax帖子使用了ember e jquery:

saveContactAndDownload() {
  this.set('showErrors', true);
  var self = this;

  if(!this.isEmpty('name') && !this.isEmpty('email') && !this.get('invalidEmail')) {
    let store = this._targetObject.store;

    let contact = store.createRecord('contact-download', {
      name: this.get('name'),
      email: this.get('email'),
    });

我的django观点:

@throttle(zone='institucional-contact')
@csrf_exempt
@require_POST
def contactdownload_contact_api(request):
    import ipdb;
    ipdb.set_trace();
    post = json.loads(request.body)
    form = ContactDownloadAPIForm(post.get('contactDownload'))
    if form.is_valid():
        contact = form.save()
        response = {'contactDownload': {'id': contact.id}}
        return HttpResponse(content=json.dumps(response), status=200)
    else:
        errors = form.errors
        msg = '<br />'.join([errors.get(error)[0] for error in errors])

        return HttpResponse(content=msg, status=400)

我的网址:

urlpatterns = patterns(
    '',
    url(r'^', include(DashboardResource().urls)),
    url(r'^', include(LoginResource().urls)),
    url(r'^', include(AgendaResource().urls)),
    url(r'^', include(ChatResource().urls)),
    url(r'^', include(MunicipioResource().urls)),
    url(r'^', include(UFResource().urls)),
    url(r'^', include(BranchResource().urls)),
    url(r'^file/upload/$', csrf_exempt(UploadResource.as_view())),
    url(r'^', include(FileTypeResource().urls)),
    url(r'^', include(DeedResource().urls)),
    url(r'^', include(api.urls)),
    url(r'^{}/contact/$'.format(api.api_name), simple_contact_api, name='simple_contact_api'),
    url(r'^{}/branch-contact/$'.format(api.api_name), branch_contact_api, name='brsanch_contact_api'),
    url(r'^{}/candidate-contact/$'.format(api.api_name), candidate_contact_api, name='candidate_contact_api'),
    url(r'^{}/contact-download/$'.format(api.api_name), contactdownload_contact_api, name='contactdownload_contact_api'),
    url(r'^{}/magazine-contact/$'.format(api.api_name), magazine_contact_api, name='magazine_contact_api'),
    url(r'^{}/partnership/$'.format(api.api_name), partnsership_contact_api, name='partnsership_contact_api'),
    url(r'^v1/search/$', search_autocomplete, name='search_autocomplete'),
    url(r'^v1/destiny-guide/$', destiny_guide, name='destiny-guide'),
)

我没有想法做什么,我的dubugging ipdb请求,但响应总是那样:

Ember Data Request POST http://dev.worldstudy.com.br:8000/api/v1/contact-download/ returned a 403
Payload (text/html)
[Omitted Lengthy HTML]
Error
    at AdapterError (http://dev.worldstudy.com.br:4200/assets/vendor.js:86531:16)
    at Class.handleResponse (http://dev.worldstudy.com.br:4200/assets/vendor.js:88146:14)
    at Class.handleResponse (http://dev.worldstudy.com.br:4200/assets/world-study-website.js:19:26)
    at Class.superWrapper [as handleResponse] (http://dev.worldstudy.com.br:4200/assets/vendor.js:50208:22)
    at ajaxError (http://dev.worldstudy.com.br:4200/assets/vendor.js:88644:25)
    at Class.hash.error (http://dev.worldstudy.com.br:4200/assets/vendor.js:88218:23)
    at fire (http://dev.worldstudy.com.br:4200/assets/vendor.js:3635:31)
    at Object.fireWith [as rejectWith] (http://dev.worldstudy.com.br:4200/assets/vendor.js:3765:7)
    at done (http://dev.worldstudy.com.br:4200/assets/vendor.js:9592:14)
    at XMLHttpRequest.<anonymous> (http://dev.worldstudy.com.br:4200/assets/vendor.js:9832:9)
defaultDispatch @ ember.debug.js:16905
dispatchError @ ember.debug.js:16888
onerrorDefault @ ember.debug.js:30389
trigger @ ember.debug.js:57833
(anonymous) @ ember.debug.js:58717
invoke @ ember.debug.js:339
flush @ ember.debug.js:407
flush @ ember.debug.js:531
end @ ember.debug.js:601
run @ ember.debug.js:724
join @ ember.debug.js:746
run.join @ ember.debug.js:21556
hash.error @ rest.js:956
fire @ jquery.js:3317
fireWith @ jquery.js:3447
done @ jquery.js:9274
(anonymous) @ jquery.js:9514

0 个答案:

没有答案