首页 > 解决方案 > 无法在我的 Django 项目中安装简单 JWT

问题描述

这是我现在的设置:

点冻结:

asgiref==3.3.1
Django==3.0
djangorestframework==3.10.0
djangorestframework-simplejwt==4.6.0
PyJWT==2.0.1
pytz==2021.1
sqlparse==0.4.1

设置.py

from pathlib import Path

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
    'snippets.apps.SnippetsConfig',
]


REST_FRAMEWORK = {
    'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
    'PAGE_SIZE': 10,
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework_simplejwt.authentication.JWTAuthentication',
    )
}

当我运行 $ python manage.py runserver 我得到这个错误

ImportError: Could not import 'rest_framework_simplejwt.authentication.JWTAuthentication' for API setting 'DEFAULT_AUTHENTICATION_CLASSES'. ModuleNotFoundError: No module named 'rest_framework_simplejwt'.

我试过像这样在 settings.py 的顶部导入它

import rest_framework_simplejwt

并尝试将其添加到我的已安装应用程序中。

没有任何工作。在这里的任何帮助将不胜感激。

另外,我正在遵循本指南: https ://django-rest-framework-simplejwt.readthedocs.io/en/latest/getting_started.html

标签: pythondjangodjango-rest-frameworkjwt

解决方案


确保您使用的是正确的环境。您运行“pip freeze”的环境与 Django 使用的 python 环境之间可能存在差异。


推荐阅读