Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static Files only found if collectstatic has been run #165

Open
iwootten opened this issue Oct 8, 2018 · 2 comments
Open

Static Files only found if collectstatic has been run #165

iwootten opened this issue Oct 8, 2018 · 2 comments

Comments

@iwootten
Copy link

iwootten commented Oct 8, 2018

PDF's can't be created using static assets and django-wkhtmltopdf unless collectstatic has been run, moving the static files into the STATIC_ROOT directory.

This isn't as per django template views in debug mode where static files are served out of their initial directory and makes development more difficult where pdfs depend on css for instance.

@iwootten iwootten changed the title Static Files not found Unless collectstatic has been run Static Files only found if collectstatic has been run Oct 8, 2018
@amirkdv
Copy link
Contributor

amirkdv commented Feb 8, 2019

This issue is deeply tied to the way that django treats static files in debug mode with runserver; django-wkhtmltopdf maintainers may be ok with not supporting this usage.

A workaround I have found is this: create a symlink from wherever STATIC_ROOT is to the "initial" directory of static files. For example, if you settings says:

import os
STATICFILES_DIR = ['path/to/some/dir']
STATIC_ROOT = os.path.abspath('static')

Notes:

  • The STATIC_ROOT variable is ignored by runserver in debug mode,
  • we cannot just make STATIC_ROOT be /path/to/some/dir since that crashes django system checks, which makes sense because you can't have STATIC_ROOT (output of collectstatic) to be inside STATICFILES_DIR (input of collectstatic). A symbolic link, however, tricks the system check into not realizing that the two paths are the same.
  • Even if you do run collectstatic in this setup you end up copying every single static files on top of itself; nothing will break.
  • This will break if you have multiple STATICFILES_DIR paths; because you can only symlink to one.

@edu2004eu
Copy link

A somewhat better option is to use the collectstatic -l built-in flag so that collectstatic creates the symlinks to each file individually, as opposed to the developer symlinking the whole static folder. The downside is that you'll have to re-run collectstatic if you create new static files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants