我正在尝试使用django和ionic制作一个应用程序,它保证我要使用django登录,并仅通过ionic发送名称和密码,但是用户会话未保持打开状态。
如果有人可以告诉我如何使用django的后端从ionic登录,就像它在浏览器中那样,以免丢失会话
#View Login in django
def login_process_IONIC(request,user,password):
print(usuario, clave)
user = authenticate(username = usuario,password = clave)
if user is not None:
login(request,user)
usuario_log = User.objects.get(username=user)
perfil = {
'last_login':str(request.user.last_login),
'is_superuser':request.user.is_superuser,
'username':request.user.username,
'first_name':request.user.first_name,
'last_name':request.user.last_name,
'email':request.user.email,
'is_active':request.user.is_active,
'date_joined':str(request.user.date_joined),
'profile':{
'country':request.user.Profile2.ubicacion,
'bio':request.user.Profile2.frase,
'image':request.user.Profile2.imagen,
}
}
info_p = json.dumps(perfil)
return HttpResponse(info_p)
这是在IONIC服务登录中
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { usuario_actual_interface } from '../../models/login_interface';
import { MenuController } from '@ionic/angular';
import { AppComponent } from '../../app.component';
@Injectable({
providedIn: 'root'
})
export class LoginService {
mensaje:string;
user_log:usuario_actual_interface;
error_autent:string = null;
constructor(
private http:HttpClient
) { }
logeologeo(user:string,password:string):Observable<usuario_actual_interface>{
return this.http.get<usuario_actual_interface>('http://192.168.1.68:8000/usuario/login_IONIC/'+user+'/'+password+'/')
}
}