I Do a form request in django with ajax but the response is always 500 and i don´t have any ideia what is wrong.
My ajax post using 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'),
});
My django view:
@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)
My url.py:
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'),
)
And i have no ideia what do , my dubugging ipdb the request is made , but the response is always that:
Ember Data Request POST http://ift.tt/2qnXWEW returned a 500 Payload (text/html) [Omitted Lengthy HTML] Error
Aucun commentaire:
Enregistrer un commentaire