python reportlab-registerFont-django-一段时间后字体不可用 [英] python reportlab - registerFont - django - font not available after some time

查看:58
本文介绍了python reportlab-registerFont-django-一段时间后字体不可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道什么是注册在reportlab中使用的字体的最佳时间.我在我的settings.py中添加了以下行:

I'm wondering what is the best time to register a font for use in reportlab. I added the following line into my settings.py:

pdfmetrics.registerFont(TTFont('Calibri', FONT_DIR + '/fonts/Calibri.ttf'))

在此调用之后,该字体可用于pdf生成.但是发生这种情况,几天后该字体不再可用,我不得不重新启动django应用,这导致了该字体的重新注册.

After this call the font is available for pdf generation. But it occurs that after a few days the font is not available anymore and I have to restart the django app, which leads to a re-registering of the font.

我已经尝试过的一种方法是在每次pdf生成调用之前注册字体,该方法不起作用,因为它在每次3-5个调用时都崩溃了.

One approach I already tried was registering the font before each pdf generation call, which did not worked since it crashed each 3-5 call.

我只想知道settings.py是否是为reportlab注册字体的正确位置,如果可以,请问几天后该字体不再可用的原因是什么??

I just want to know if the settings.py is the correct place to register a font for reportlab and if yes, what could be the reason that the font is not available after a few days anymore!?

-编辑-

实际上,我们发现reportlab和mod-wsgi存在一些问题.我们改用fast-cgi,再也看不到这个问题了.

actually we discovered that there are some issues with reportlab and mod-wsgi. we switched to fast-cgi and never saw this problem again.

推荐答案

我不知道报告实验室的工作原理,但是我可以说Django.

I don't know what anything about how reportlabs works, but I can say about django.

Django不保证设置将被一次导入(可能存在任何其他问题),并且对于此类事情不是一个好地方.通常,urls.py用于对象注册(例如admin.autodiscover).

Django doesn't warrant that settings will be imported once (may be, there are any other problems) and it's not a good place for such things. Usually, urls.py is used for objects registration (for example, admin.autodiscover).

这篇关于python reportlab-registerFont-django-一段时间后字体不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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