管理员部分中的Model Token的用途是什么? [英] What is the purpose of model Token in the admin section?

查看:72
本文介绍了管理员部分中的Model Token的用途是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对其余的api很陌生.我正在尝试将 dj-rest-auth 包与 simple-jwt 一起使用以进行身份​​验证处理.在我的项目中一切正常.注册/登录等.但是在我的django管理站点中,有一个模型注册的 Token ,每次都为空.此模型 Token 的目的是什么?如何使用 dj-rest-auth simple jwt 软件包管理令牌?

I am fairly new to the rest api. I am trying to use dj-rest-auth package with simple-jwt for auth handling. Everything works fine in my project. The registration/login etc. But in my django admin site there is a model registered Token which is every time empty. What is the purpose of this model Token? How tokens are managed with dj-rest-auth and simple jwt package ?

settings.py

settings.py

installed_apps= [
..
    'rest_framework',
    'rest_framework.authtoken',
    'dj_rest_auth',
    'django.contrib.sites',
    'allauth',
    'allauth.account',
    'allauth.socialaccount',
    'dj_rest_auth.registration',



REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework_simplejwt.authentication.JWTAuthentication',
    )

}

REST_USE_JWT = True
SIMPLE_JWT = {
    'ACCESS_TOKEN_LIFETIME': timedelta(minutes=5),
    'REFRESH_TOKEN_LIFETIME': timedelta(days=7),
}


ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = "mandatory"
ACCOUNT_EMAIL_CONFIRMATION_EXPIRE_DAYS = 1
ACCOUNT_AUTHENTICATION_METHOD = "username"
ACCOUNT_LOGIN_ATTEMPTS_LIMIT = None

urls.py

path('user/', include('dj_rest_auth.urls')),
path('user/register/', include('dj_rest_auth.registration.urls')),
path('confirm/email/', CustomVerifyEmailView.as_view(), name='account_email_verification_sent'),

推荐答案

您在管理员中具有 Token 模型,因为您已将 rest_framework.authtoken 添加到已安装的应用程序中.此模型用于基本令牌(存储在数据库中)身份验证: https://www.django-rest-framework.org/api-guide/authentication/#tokenauthentication

You have Token model in admin because you added rest_framework.authtoken to your installed apps. This model is for basic token (stored in db) authentication: https://www.django-rest-framework.org/api-guide/authentication/#tokenauthentication

JWT(JSON Web令牌)令牌是无状态的,并且不存储在db中.如果您想了解有关JWT的更多信息,我建议: https://jwt.io/introduction

JWT (JSON Web Tokens) tokens are stateless and are not stored in db. If you want to read more about JWT I recommend: https://jwt.io/introduction

这篇关于管理员部分中的Model Token的用途是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆