6176964bdf
* Reorder and clarify the 'Request Data' guide, adding a section on RequestParameters * Clarify routing guide, adding introduction and HTTP types sections * Clarify the use-cases of middleware * Clean up formatting in the exceptions guide and add some common exceptions. * Fix formatting of blueprints and add use-case example. * Clarify the class-based views guide * Clarify and fix formatting of cookies guide * Clarify static files guide * Clarify the custom protocols guide. * Add more information to the deploying guide * Fix broken list in the community extensions list. * Add introduction and improve warning to contributing guide * Expand getting started guide * Reorder guides and add links between them * Standardise heading capitalisation
24 lines
660 B
Markdown
24 lines
660 B
Markdown
# Static Files
|
|
|
|
Static files and directories, such as an image file, are served by Sanic when
|
|
registered with the `app.static` method. The method takes an endpoint URL and a
|
|
filename. The file specified will then be accessible via the given endpoint.
|
|
|
|
```python
|
|
from sanic import Sanic
|
|
app = Sanic(__name__)
|
|
|
|
# Serves files from the static folder to the URL /static
|
|
app.static('/static', './static')
|
|
|
|
# Serves the file /home/ubuntu/test.png when the URL /the_best.png
|
|
# is requested
|
|
app.static('/the_best.png', '/home/ubuntu/test.png')
|
|
|
|
app.run(host="0.0.0.0", port=8000)
|
|
```
|
|
|
|
**Previous:** [Deploying](deploying.html)
|
|
|
|
**Next:** [Middleware](middleware.html)
|