0

I've been trying to have a simple Get Request work with my Angular/Django setup but the route doesn't seem to be able to find the Backend Django routes.

I am passing the data as a query string parameter. At first it was giving me an error which I fixed using this thread:

Angular 6: HttpErrorResponse SyntaxError: Unexpected token s in JSON

Now it doesn't give me any error at all. However, I know it never finds my route in my Backend Django. I've been trying to solve this simple error for 3 days now, any help would be appreciated.

The route I am on: http://127.0.0.1:8000/registration

user.service.ts:

export class UserService {

  httpHeaders = new HttpHeaders({'Content-Type': 'application/json; charset=utf-8'})

  constructor(private _http : HttpClient) { }

  checkEmailNotTaken(values: any): Observable<any> {
    console.log("SERVICE: Check Email");
    console.log(values);

    let params = new HttpParams();
    params = params.append('email', values);

    return this._http.get('/UserEmail/', {headers: this.httpHeaders, params: params, responseType:'text' as 'json'});
  }
}

urls.py:

urlpatterns = [

    path('UserEmail/<email>', viewsCRUD.getUserByEmail)

]

views.py:

@api_view(['GET', 'POST'])
def getUserByEmail(request):
    print(request)
    print(request.GET)

Python/Django Terminal:

[11/May/2019 21:14:21] "GET /UserEmail?email=david@g HTTP/1.1" 200 831

Snoopy
  • 41
  • 1
  • 5
  • You say that in the Django terminal you can see `[11/May/2019 21:14:21] "GET /UserEmail?email=david@g HTTP/1.1" 200 831` so, the request from angular it is reaching Django. Perhaps the view is not returning what you're expecting? – Raydel Miranda May 12 '19 at 04:43
  • It is reaching django but it isn't activating the Route in urls.py. I know that because the view isn't even executing. – Snoopy May 12 '19 at 11:46

1 Answers1

0

You are getting non-json as reponse which is a string starting with 's'.

Try to find out the response coming from the API

prisar
  • 3,041
  • 2
  • 26
  • 27