0

I spent many time for this work but no result for me... so I want someone can help me!! I used to use http post method of Angular JS 2 like this:

login(email:string, password:string) {
     let headers = new Headers();
     headers.append('Content-Type', 'application/json');
     headers.append('X-CSRFToken', this.getCookie('csrftoken'));
     return this.http
     .post(
        '/accounts/login', 
        JSON.stringify({ email, password }), 
        { headers }
     ).map(response => console.log(response))

 }

It accessed to server with url : "/accounts/login" successfully, but when I print data post with command in django : print request.POST It shows for me : <QueryDict: {}>, I don't why QueryDict empty,

this is my form.html :

  <div class="login jumbotron center-block">
   <h1>Login</h1>
   <form role="form" (submit)="login(event,username.value,         password.value)">
      <div class="form-group">
        <label for="username">Username</label>
        <input type="text" #username class="form-control" id="username" placeholder="Username">
      </div>
      <div class="form-group">
        <label for="password">Password</label>
        <input type="password" #password class="form-control" id="password" placeholder="Password">
      </div>
      <button type="submit" class="btn btn-default">Submit</button>
        <a [routerLink]="['/signup']">Click here to Signup</a>
  </form>
</div>

... I can sure that is email and password not null !!

0 Answers0