I have build my frontend using Angular and backend using django-restframwork. In my settings.py I provided CORS_ORIGIN_ALLOW_ALL = True
I run it using python3.8 manage.py runserver 5000
but when my frontend tried to send request to it it generates error.
my angular sends request like this.
my environment file where I saved my urls
export const environment = {
production: true,
api_url: "https://localhost:5000/op-api",
user_login_url: "https://localhost:5000/auth/login/",
// all_users :"https://ots.ahg.af:5000/rest-auth/login",
user_logout_url: "https://localhost:5000/auth/logout/",
user_register_user:"https://localhost:5000/auth/register/"
};
and by submitting register form I send my request like this.
onCreateAccount(){
this.httpService.register_user(this.registerForm.value).subscribe(resp=>{
.......
}, error=>{
......
} else{
........
});
}
these are in my http service where I call using the above code.
user_register_user = environment.user_register_user;
public register_user(data){
if (data != null){
return this.http.post(this.user_register_user ,{
'username': data.username,
'email' : data.email,
'password' : data.password,
});
}
}
can anyone tell me why I am getting cross-origin error and what is the problem.
I tried:
export const environment = {
production: true,
api_url: "https://ots.ahg.af:5000/op-api",
user_login_url: "https://ots.ahg.af:5000/auth/login/",
// all_users :"https://ots.ahg.af:5000/rest-auth/login",
user_logout_url: "https://ots.ahg.af:5000/auth/logout/",
user_register_user:"https://ots.ahg.af:5000/auth/register/"
};
ots.ahg.af is my domain name
export const environment = {
production: true,
api_url: "http://127.0.0.1:5000/op-api",
user_login_url: "http://127.0.0.1:5000/auth/login/",
// all_users :"http://127.0.0.1:8000/rest-auth/login",
user_logout_url: "http://127.0.0.1:5000/auth/logout/",
user_register_user:"http://127.0.0.1:5000/auth/register/"
};
none of the above worked for me.