zoukankan      html  css  js  c++  java
  • python3 + Django + Vue + Element-UI 开发坑点记录

    一、ERROR  generateImage failed.生成图片失败  cannot open resource

    错误日志:

    2021-06-29 11:04:11 | ERROR generateImage failed.生成图片失败 cannot open resource
    Traceback (most recent call last):
    File "/home/****/Post/utils.py", line 186, in generateImage
    fnt = ImageFont.truetype("simsun.ttc", font_size, encoding="unic")
    File "/usr/local/lib64/python3.6/site-packages/PIL/ImageFont.py", line 853, in truetype
    return freetype(font)
    File "/usr/local/lib64/python3.6/site-packages/PIL/ImageFont.py", line 850, in freetype
    return FreeTypeFont(font, size, index, encoding, layout_engine)
    File "/usr/local/lib64/python3.6/site-packages/PIL/ImageFont.py", line 210, in __init__
    font, size, index, encoding, layout_engine=layout_engine
    OSError: cannot open resource

    问题分析:

    本地开发环境调试没问题,发布至线上后,生成图片失败。怀疑是linux没安装simsun.ttc的字体。尝试换了一些字体,均未解决。

    网上查了下,方法有两种。

    一是给linux服务端安装中文字体。但公司线上发布已服务化,每次发布或重启都会更换容器,未采取。

    第二种方法,比较简单、暴力。将字体文件放到项目的src中,ImageFont.truetype指定该字体,从而解决跨环境问题

    fontPath = os.path.join(settings.BASE_DIR, r"src/simsun.ttc")
    fnt = ImageFont.truetype(fontPath, font_size, encoding="unic")

    二、vue的静态图片src/assets/image,在打包时,未能打包至dist/static/img下

      前端不太熟,纠结了很久。原因是需要在.vue文件中,引用src/assets/image下的图片,通过webpack打包时,才会自动打包至dist/static/img下

    陈月白 http://www.cnblogs.com/chenyuebai
  • 相关阅读:
    CF219D
    HDU 4259 Double Dealing 数学题
    HDU1599 find the mincost route 最小环
    HDU3592 World Exhibition 排队判断3种情况
    POJ3694 Network 加边查询剩余桥的个数
    Flex 如何获得Tree 拖动节点的起始位置
    wcf webconfig配置
    学JS面向对象 以及里面的继承
    sqlserver 几种查询耗时
    ubuntu更改文件夹属性
  • 原文地址:https://www.cnblogs.com/chenyuebai/p/14958656.html
Copyright © 2011-2022 走看看