【Python2转换升级Python3异常错误更改】(四)

目录

33.ImportError: cannot import name 'six' from 'django.utils'

34.ModuleNotFoundError: No module named 'django.utils.six'

35.ImportError: cannot import name 'cookie_date' from 'django.utils.http'

36.ImportError: cannot import name 'urlresolvers' from 'django.core'

37.ImportError: cannot import name 'patterns' from 'django.conf.urls'

38.ModuleNotFoundError: No module named 'copy_reg'

39.NameError: name 'unicode' is not defined

40.AttributeError: module 'types' has no attribute 'ClassType'

41.AttributeError: module 'types' has no attribute 'InstanceType'

42.ValueError: The 'hive' package was not installed in a way that PackageLoader understands.

43.ImportError: cannot import name 'soft_unicode' from 'markupsafe'

44.AttributeError: module 'urllib' has no attribute 'quote'

45.django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues:

ERRORS:

?: (urls.E007) The custom handler404 view 'hive.shared.custom_404_view' does not take the correct number of arguments (request, exception).

46.create user_operation_log faild: module 'jwt' has no attribute 'decode'


33.ImportError: cannot import name 'six' from 'django.utils'

解决:
改为
import six

34.ModuleNotFoundError: No module named 'django.utils.six'

six.py放入django.utils下

35.ImportError: cannot import name 'cookie_date' from 'django.utils.http'

解决:
python3 django3不支持cookie_date 改为
http_date

36.ImportError: cannot import name 'urlresolvers' from 'django.core'

解决:
django1.3以后不支持 urlresolvers 改为
from django.urls import reverse

37.ImportError: cannot import name 'patterns' from 'django.conf.urls'

解决:
从1.10后django后patterns被移除了,已经没有这个模块了。使用 django 1.10 以后的版本需要改用 django.conf.urls.url() 
from django.conf.urls import patterns,include,url
from django.contrib import admin
from helloworld.views import hello
​
示例:
from django.conf.urls import patterns,include,url
urlpatterns = patterns('',
    url(r'^admin/', include(admin.site.urls)),
    url(r'^helloworld$', hello),
)
改为
from django.conf.urls import url,include
​
urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'^helloworld$', hello),
]

38.ModuleNotFoundError: No module named 'copy_reg'

解决:
copy_reg 在python3 被废除
使用
copyreg

39.NameError: name 'unicode' is not defined

解决:
# python 3 doesn't have a unicode type
try:
    unicode
except:
    unicode = str

40.AttributeError: module 'types' has no attribute 'ClassType'

解决:
/usr/local/python3/lib/python3.7/types.py 加
class _C:
    def _m(self): pass
ClassType = type(_C)

41.AttributeError: module 'types' has no attribute 'InstanceType'

解决:
/usr/local/python3/lib/python3.7/types.py 加
_x = _C()
InstanceType = type(_x)

42.ValueError: The 'hive' package was not installed in a way that PackageLoader understands.

解决:
jinja2原本为3.1.2版本,降低版本至2.11.2
pip3 install jinja2==2.11.2

43.ImportError: cannot import name 'soft_unicode' from 'markupsafe'

解决:
soft_unicode 改为 soft_str

44.AttributeError: module 'urllib' has no attribute 'quote'

解决:
from urllib.parse import quote
urllib.parse 导入quote

45.django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues:

ERRORS:

?: (urls.E007) The custom handler404 view 'hive.shared.custom_404_view' does not take the correct number of arguments (request, exception).

如图新增代码解决问题

46.create user_operation_log faild: module 'jwt' has no attribute 'decode'

解决:
# jwt卸载命令
pip uninstall jwt
# 保险起见,将PyJWT一同卸载
pip uninstall PyJWT
# 重新安装PyJWT
pip install PyJWT

该系列已经完结,若有不明白的地方可以私信咨询我~ 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值