python reportlab - registerFont - django - font not available after some time

拟墨画扇 提交于 2019-12-11 03:55:47

问题


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'))

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.

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.

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!?

--Edit--

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


回答1:


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

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).



来源:https://stackoverflow.com/questions/2628377/python-reportlab-registerfont-django-font-not-available-after-some-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!