升级Django项目过程中问题记录
升级内容:
python版本:3.8.4升到3.10.7
Django版本:2.2.13升到4.2
所遇问题:
1、 error in anyjson setup command: use_2to3 is invalid.
pip3 install setuptools==57.5.0 # 降到58以下即可,因为58之后不再有use_2to3
2、ImportError: cannot import name 'python_2_unicode_compatible' from 'django.utils.encoding'
3、ImportError: cannot import name 'ugettext_lazy' from 'django.utils.translation'
4、File "lib/python3.10/site-packages/multiselectfield/db/fields.py", line 80, in __init__
self.validators[0] = MaxValueMultiFieldValidator(self.max_length)
IndexError: list assignment index out of range
if len(self.validators) == 0: self.validators.append(None)
5、raise InvalidTemplateLibrary(
django.template.library.InvalidTemplateLibrary: Invalid template library specified. ImportError raised when trying to load 'rest_framework.templatetags.rest_framework': cannot import name 'parse_header' from 'django.http.multipartparser'
pip install djangorestframework --upgrade
6、ImportError: Could not import 'rest_framework_jwt.authentication.JSONWebTokenAuthentication' for API setting 'DEFAULT_AUTHENTICATION_CLASSES'. ModuleNotFoundError: No module named 'rest_framework_jwt'.
pip install djangorestframework-jwt
7、ImportError: Could not import 'rest_framework_jwt.authentication.JSONWebTokenAuthentication' for API setting 'DEFAULT_AUTHENTICATION_CLASSES'. ImportError: cannot import name 'smart_text' from 'django.utils.encoding'
pip install djangorestframework-simplejwt
REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': ( 'rest_framework_simplejwt.authentication.JWTAuthentication', ) }