D
D
Danil Valiulin2015-01-08 20:03:10
Django
Danil Valiulin, 2015-01-08 20:03:10

Why does the server return an error 500 when submitting a form using $http.post?

Submitting a form using AngularJS:

var app = angular.module('reg_app', []);

app.config(['$httpProvider', function($httpProvider) {
  $httpProvider.defaults.xsrfCookieName = 'csrftoken';
    $httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken';
}]);

app.controller('RegFormController', ['$scope', '$http', function($scope, $http) {
  $scope.submit = function() {
    var in_data = {user: $scope.user};
    console.log(in_data);
    $http.post('/reg/', in_data)
      .success(function(data, status, headers, config) {
        successCallback(data);
      })
      .error(function(data, status, headers, config) {
        console.log('NOT OK')
      });
  };
}]);

In the browser console it says:
POST 127.0.0.1:8000/reg 500 (INTERNAL SERVER ERROR)
Django returns False on request.is_ajax(), but:
in_data = json.loads(request.body)
    print(in_data)

returns:
{u'user': {u'username': u'test', u'password': u'test'}}
I can't figure out why the server returns error 500?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Abramov, 2015-01-08
@kivsiak

Look at the server logs. Everything is written there.

A
Alexey P, 2015-01-09
@ruddy22

- look at how the API works, there may be an error there
- read the API documentation for the server
- are you sending the data correctly? (I'm confused by this line {user: $scope.user};)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question