Static Files¶
Ushka provides a simple way to serve static files like CSS, JavaScript, and images. This feature is enabled by default.
Configuration¶
The static file server is configured in the [static] section of your ushka.toml file.
The default configuration looks like this:
[static]
# Enables or disables the feature
enable = true
# The URL prefix for static files
url = "/static"
# The directory in your project where static files are located
dir = "static"
With this configuration, any file placed in the my_project/static/ directory will be served under the /static/ URL.
For example, a file at my_project/static/css/style.css will be accessible at the URL http://yourdomain.com/static/css/style.css.
Usage in Templates¶
You can reference your static files in Jinja2 templates using the configured URL prefix.
<!DOCTYPE html>
<html>
<head>
<title>My App</title>
<link rel="stylesheet" href="/static/css/style.css">
</head>
<body>
<h1>Hello, World!</h1>
<img src="/static/images/logo.png" alt="Logo">
<script src="/static/js/main.js"></script>
</body>
</html>
Disabling Static File Serving¶
If you are serving your static files through a different web server (like Nginx) or a CDN in production, you can disable Ushka's static file server for that environment.
Simply set enable to false in ushka.toml: