python reportlab - registerFont - django - font no

2019-07-19 07:39发布

问题:

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