Skip to content

Commit dac68d2

Browse files
committed
Made example that shows manual static files handling more verbose
1 parent f03f49e commit dac68d2

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

docs/examples.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,15 @@ In order to save memory, we are unregistering unused MIME types and registering
5858
:linenos:
5959

6060
You can also serve a specific file from the handler.
61-
By default ``FileResponse`` looks for the file in the server's ``root_path`` directory, but you can change it.
61+
By default ``FileResponse`` looks for the file in the server's ``root_path`` directory
62+
(``/default-static-directory`` in the example below), but you can change it manually in every ``FileResponse``
63+
(to e.g. ``/other-static-directory``, as in example below).
64+
65+
By doing that, you can serve files from multiple directories, and decide exactly which files are accessible.
6266

6367
.. literalinclude:: ../examples/httpserver_handler_serves_file.py
6468
:caption: examples/httpserver_handler_serves_file.py
65-
:emphasize-lines: 22
69+
:emphasize-lines: 13,22
6670
:linenos:
6771

6872
.. literalinclude:: ../examples/home.html

examples/httpserver_handler_serves_file.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010

1111

1212
pool = socketpool.SocketPool(wifi.radio)
13-
server = Server(pool, "/static", debug=True)
13+
server = Server(pool, "/default-static-folder", debug=True)
1414

1515

1616
@server.route("/home")
1717
def home(request: Request):
1818
"""
19-
Serves the file /www/home.html.
19+
Serves the file /other-static-folder/home.html.
2020
"""
2121

22-
return FileResponse(request, "home.html", "/www")
22+
return FileResponse(request, "home.html", "/other-static-folder")
2323

2424

2525
server.serve_forever(str(wifi.radio.ipv4_address))

0 commit comments

Comments
 (0)