How to bring AngularJS app and Flask on same domain?

python angularjs flask

145 просмотра

1 ответ

1200 Репутация автора

I have created a web application in AngularJS and a Flask server up and running on localhost:5000/. I wanted to make a login service, so I included the following code in my controller in AngularJS:

$scope.login = function() {
            $http({
              method: 'POST',
              data: {
                username: $scope.username,
                password: $scope.password
              },
              url: 'http://127.0.0.1:5000/login/'
            }).then(function successCallback(response) {
                console.log('successCallback')
              }, function errorCallback(response) {
                console.log('errorCallback')
              });
}

I call the login() method from the UI. But this gives me the following error:

XMLHttpRequest cannot load http://127.0.0.1:5000/login/. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

Further when I researched on this error, I found this link, which states that my page is on a different domain than my server. How do I bring my AngularJS and python server on same domain? What piece of code will I have to specify so that in place of url:'http://127.0.0.1:5000/login/', I just have to specify '/login'? I know this might be trivial question, but please guide me.

Автор: Prabhjot Rai Источник Размещён: 18.07.2016 03:28

Ответы (1)


0 плюса

46145 Репутация автора

Change app.run in flask code and your url all to 127.0.0.1 and then browse 127.0.0.1, then it will work.

Автор: zs2020 Размещён: 15.05.2017 03:35
Вопросы из категории :
32x32