Django-rest-auth - Angular - 500 internal error

1.4k views Asked by At

More or less, i am in the early stages developing an app that use Django Rest Framework and Angular. I decided to use django-rest-auth to manage all my user integration with my app.

As I am new in Angular, i don't want to use django-rest-auth Boilerplate Angular app in order to understand the concepts of Angular. I just want to use django-rest-auth endpoints.

The problem is: My registration form throughs an Internal Server 500 even that my data are passed and successfully submitted to django.User model.

Here is my Angular app:

// MODULE

var menuApp = angular.module('menuApp', ['ngRoute', 'ngCookies']);

//ROUTES
menuApp.config(function ($locationProvider, $routeProvider) {

$locationProvider.html5Mode({
enabled: true,
requireBase: false,
    hashPrefix:'!'
})

$routeProvider

.when('/', {
    templateUrl: '/static/app/pages/login.html',
    controller: 'homeCtrl'
})
.when('/register', {
    templateUrl: 'static/app/pages/register.html',
    controller: 'registerCtrl'
})

 menuApp.controller('homeCtrl', ['$log', '$scope', function($log,    $scope) {
        $log.info("homeCtrl is called ");
}]);

 menuApp.controller('registerCtrl', ['$scope', '$cookies', '$http','$location',
                                                function($scope, $cookies, $http, $location) {

        console.log("registerCtrl is called");

        $scope.register = function(email, username, password){
        var data = {
            'username': username,
            'password1': password,
            'password2': password,
            'email': email
        }
        console.log(data)

        var make_registration = $http({
                url: "/api/rest-auth/registration/",
                method: "POST",
                headers: {
                    'X-CSRFToken': $cookies.token,
                    'Content-Type': 'application/json'},
                data: data,
                    })
        .success(function(data, status, headers) {
            console.log($cookies.csrftoken)
            console.log(data);
            console.log(status);
            console.log(headers);
        })
        .error(function(data, status, headers) {
                            // Need a minimal function to pass the errors
                            console.log(status);
                            console.log(data);
        });
        return make_registration
            }

   }]);

  // RUN
 menuApp.run(function ($http) {
    $http.defaults.xsrfHeaderName = 'X-CSRFToken';
    $http.defaults.xsrfCookieName = 'csrftoken';
 });

My form is a very simple one with a 'ng-submit="register(email, username, password)' and 3 inputs ng-model='email' etc.

My urls :

urlpatterns = patterns('',

 url(r'^admin/', include(admin.site.urls)),
 url(r'^api/rest-auth/', include('rest_auth.urls')),
 url(r'^api/rest-auth/registration/',
        include('rest_auth.registration.urls')),
 url('^.*$', IndexView.as_view(), name='index'),
)
2

There are 2 answers

0
Felipe Santos On

I had the exactly same problem, and turns out that the 500 internal error was raised when django-allauth tried to send an confirmation email, but failed because I didn't have an STMP server running.

Assuming that your problem is similar to mine, just add this line on your settings.py:

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
0
user1376455 On

you need django-allauth for registration to work.

from Docs

Registration (optional)

If you want to enable standard registration process you will need to install django-allauth - see this doc for installation Add allauth, allauth.account and rest_auth.registration apps to INSTALLED_APPS in your django settings.py: