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
How to serve static files in a directory #425
Comments
There is an example of serving an image file using hug (path to served image is wrong and fixed in #426). For a static HTML page one would only need to set proper output format: Does this solve the issue? If not, then what would you change/improve? |
@spock thanks for your consideration! The example is about one single file, I would like to serve all files from a directory without |
It already works as the example in my pull-request #429 shows. a) the function decorated with hug.static() seems to be called before hug.startup() functions. b) how are the filetypes determined? |
regarding b), I'd guess its output_format.file |
Not having any luck with this using a PNG file. Is there another recommended way to do this?
Thank you! |
@teran-mckinney if you are trying to serve all files from a directory, then consider trying my example code at #429 . Should be something like (untested): @hug.static('/static')
def my_static_dirs():
 return('/home/www/path-to-static-dir',) |
Another solution here. https://gist.github.com/m-ueno/0ec3922c30c37424f13bcaecc98ab4db |
Looks like this question has been answered well, closing and will remember to expand the documentation, thanks everyone! |
It would be nice if there was an example how to serve static files from a directory from within hug, so that other hug mechanisms, like authentication work. This can be needed to load a single page web application. (For example I am using hug as a prototyp serving backend in https://github.com/Intevation/intelmq-fody where it would be useful to serve the static files.)
In #43 (comment) the need for this can be seen. (There not solved by hug, but by pecan using
static
..)The text was updated successfully, but these errors were encountered: