Made static file serving part of Sanic

Added sanic.static, blueprint.static, documentation, and testing
This commit is contained in:
Channel Cat
2016-10-24 01:21:06 -07:00
parent d7fff12b71
commit bf6879e46f
14 changed files with 209 additions and 52 deletions

View File

@@ -42,7 +42,7 @@ from sanic import Sanic
from my_blueprint import bp
app = Sanic(__name__)
app.register_blueprint(bp)
app.blueprint(bp)
app.run(host='0.0.0.0', port=8000, debug=True)
```
@@ -79,6 +79,12 @@ Exceptions can also be applied exclusively to blueprints globally.
@bp.exception(NotFound)
def ignore_404s(request, exception):
return text("Yep, I totally found the page: {}".format(request.url))
## Static files
Static files can also be served globally, under the blueprint prefix.
```python
bp.static('/folder/to/serve', '/web/path')
```
## Start and Stop

18
docs/static_files.md Normal file
View File

@@ -0,0 +1,18 @@
# Static Files
Both directories and files can be served by registering with static
## Example
```python
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('/home/ubuntu/test.png', '/the_best.png')
app.run(host="0.0.0.0", port=8000)
```