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