Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Static file in Django wkhtmltopdf

I have a problem with generating a PDF file - django does not provide for wkhtmltopdf static files if the path looks like this:

<link rel="stylesheet" type="text/css" href="{% static 'flot/fms.css' %}">

but if I give a direct path it works:

<link rel="stylesheet" type="text/css" href="http://localhost:8000/static/flot/fms.css">

The problem with static files is only when generating PDF from web, from console files generate correctly.

like image 314
MalT Avatar asked Nov 01 '22 14:11

MalT


1 Answers

You need to properly configure STATIC_ROOT and STATIC_URL for production. Depending on STATICFILES_DIRS and what STATICFILES_FINDERS you have configured, your static sources will be located together with your application's sources, while the STATIC_ROOT must be outside the path of your sources since this data is transient by nature.

This means that you must rely on running $ python manage.py collectstatic in production. Paths matching STATIC_URL should be handled by your web server, with the root configured to match STATIC_ROOT from where the files will be served.

You can review the django.contrib.staticfiles app guide and the guide on deploying static files in production from the documentation for more nitty-gritty details.

like image 74
Filip Dupanović Avatar answered Nov 08 '22 09:11

Filip Dupanović