首页 > 解决方案 > 我在 DRF+Angular 中的实现无法区分角色

问题描述

我已经实现了一个使用 django 作为后端和 angular 作为前端的登录系统。

在后端,身份验证是通过与 auth/signup 关联的视图实现的

from django.contrib import admin
from django.urls import include, path
from rest_framework import routers

from shopping.views import listatodoseventos

from rest_framework_jwt.views import obtain_jwt_token, refresh_jwt_token

urlpatterns = [
    path('admin/', admin.site.urls),
    path('api-auth/', include('rest_framework.urls')),
    path('events',listatodoseventos),
    path('auth/', include('rest_auth.urls')),
    path('auth/signup/', include('rest_auth.registration.urls')),
    path('auth/refresh-token/', refresh_jwt_token) 
]

在前端是通过这种方法完成的


  signup(username:string, email:string, password1:string, password2:string){
    //todo
    return this.http.post(
      this.apiRoot.concat('signup/'),
      {username, email, password1, password2}
    ).pipe(
      tap(response=>this.setSession(response)),
      shareReplay()
    );
  }

It generates me these tables related with users.
I want to associate each user with a role.
But I don't know how to do that cause I don't know how to create entries in auth_user_groups

链接到表格

标签: pythondjangoangulardjango-rest-framework

解决方案


推荐阅读