question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

StaticFiles support for directories other than "statics"

See original GitHub issue

Checklist

  • [/] There are no similar issues or pull requests for this yet.
  • [X - tried to get feedback but no replies] I discussed this idea on the community chat and feedback is positive.

Is your feature related to a problem? Please describe.

I want to be able to serve static files from arbitrary locations within a python package but I can’t because currently it looks in a statics folder which is hardcoded.

Describe the solution you would like.

I’d like to be able to pass as a parameter the path within the python package to look in for the static files.

Describe alternatives you considered

I’ve considered changing the location of my packaged files to statics but this will have knock on effects across other systems, and statics itself is non-standard as far as I can tell.

Additional context

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
florimondmancacommented, Dec 6, 2021

Hi folks, we’re considering #1350 and the following API to address this use case…

routes=[
    ...
    Mount('/static', app=StaticFiles(packages=['bootstrap4', ('mypackage', 'dist')]), name="static"),
]

That is, we’ll be able to specify a root directory to look into as a 2-tuple (<package_name>, <dir>) form, where the single string "<package_name>" uses the current default, "statics".

Any thoughts or comments welcome on the PR before we move on and merge. 😃

0reactions
paulmsmithcommented, Oct 20, 2021

I found that by simply creating an empty directory called statics inside the dependancy this then worked and seemed to allow me to reference things in static within the dependancy. This feels like bug to me and as @bram2000 said, would be helpful if you could pass a parameter specifying the directory within a dependancy you need to include things from.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Django created staticfiles folder rather than static folder
First it collect static files from STATICFILES_DIRS if any, if there is no STATICFILES_DIRS in settings it collects static files from each app ......
Read more >
Static files in ASP.NET Core | Microsoft Learn
Static files, such as HTML, CSS, images, and JavaScript, are assets an ASP.NET Core app serves directly to clients by default. Serve static...
Read more >
How to manage static files (e.g. images, JavaScript, CSS)
Set the STATIC_ROOT setting to the directory from which you'd like to serve these files, for example: STATIC_ROOT = "/var/www/example.com/static/" · Run the ......
Read more >
How to setup static files in Django - PythonAnywhere help
... if you want to use a static URL prefix other than /static/ ... in settings.py defines the single folder you want to...
Read more >
Static Files - FastAPI
You can serve static files automatically from a directory using StaticFiles . ... All these parameters can be different than " static ",...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found