Django Rest Framework + AngularJS not logging user in or throwing errors -


this urls.py:

from django.conf.urls import url django.conf.urls import include cmsapp import views  urlpatterns = [     url(r'^$', views.homepageview.as_view()),     url(r'^users$', views.user_list.as_view()),     url(r'^users/(?p<pk>[0-9]+)$', views.user_detail.as_view()),     url(r'^api-auth/', include('rest_framework.urls',                                    namespace='rest_framework')), ] 

so login, use url /api-auth/login. when go /api-auth/login, see drf login screen. if type in incorrect username , password, says:

please enter correct username , password. note both fields may case-sensitive. 

and if type in correct username , password, redirects page login_redirect_url in settings.py, part works.

however, want able log in without accessing drf login page. when user visits

127.0.0.1/ 

this view gets called:

class homepageview(templateview):     template_name = "home.html"      def get_context_data(self, **kwargs):             context = super(homepageview, self).get_context_data(**kwargs)             return context 

and home.html:

<h3>login</h3> <form ng-submit="ctrl.loginuser()" name="myloginform">     <div class="form-group">         <label>username</label>         <input type="text" name="uname" class="form-control" ng-model="ctrl.user.username" required>      </div>      <div class="form-group">         <label>password</label>         <input type="password" name="pwd" class="form-control" ng-model="ctrl.user.password" required>     </div>      <input type="submit" value="login">  </form>  <script> angular.module("notesapp", [])     .config(['$httpprovider', function($httpprovider) {         $httpprovider.defaults.xsrfcookiename = 'csrftoken';         $httpprovider.defaults.xsrfheadername = 'x-csrftoken';     }])      .controller("mainctrl", ["$http", function($http) {     var self = this;     self.users = {};     var fetchusers = function() {         return $http.get("/cms/users").then(function(response) { // list of existing users             self.users = response.data;         }, function(errresponse) {         console.error("error while fetching users.");         });     };      self.loginuser = function() {         $http.post("/cms/api-auth/login/", self.user)         .error(function(data, status, headers, config) {             console.log(data);          })         .then(fetchusers);          console.log("success login ", self.user);     };     }]); </script> 

the issue is, if user puts in incorrect username , password, "success login self.user" appears on console.log , there no error message. on top of that, if user logs in correct username , password, user not redirected loign_redirect_url. idea why?


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -