diff --git a/.nojekyll b/.nojekyll new file mode 100644 index 0000000000..e69de29bb2 diff --git a/404.html b/404.html new file mode 100644 index 0000000000..e02a49f5e1 --- /dev/null +++ b/404.html @@ -0,0 +1,494 @@ + + + +
+ + + + + + + + + + + + + + + + +Starlette includes an application class Starlette
that nicely ties together all of
+its other functionality.
from starlette.applications import Starlette
+from starlette.responses import PlainTextResponse
+from starlette.routing import Route, Mount, WebSocketRoute
+from starlette.staticfiles import StaticFiles
+
+
+def homepage(request):
+ return PlainTextResponse('Hello, world!')
+
+def user_me(request):
+ username = "John Doe"
+ return PlainTextResponse('Hello, %s!' % username)
+
+def user(request):
+ username = request.path_params['username']
+ return PlainTextResponse('Hello, %s!' % username)
+
+async def websocket_endpoint(websocket):
+ await websocket.accept()
+ await websocket.send_text('Hello, websocket!')
+ await websocket.close()
+
+def startup():
+ print('Ready to go')
+
+
+routes = [
+ Route('/', homepage),
+ Route('/user/me', user_me),
+ Route('/user/{username}', user),
+ WebSocketRoute('/ws', websocket_endpoint),
+ Mount('/static', StaticFiles(directory="static")),
+]
+
+app = Starlette(debug=True, routes=routes, on_startup=[startup])
+
starlette.applications.Starlette
(debug=False, routes=None, middleware=None, exception_handlers=None, on_startup=None, on_shutdown=None, lifespan=None)Creates an application instance.
+Parameters:
+ServerErrorMiddleware
is added as the very outermost middleware, to handle
+any uncaught errors occurring anywhere in the entire stack.
+ExceptionMiddleware
is added as the very innermost middleware, to deal
+with handled exception cases occurring in the routing or endpoints.handler(request, exc) -> response
and may be either standard functions, or
+async functions.on_startup
and on_shutdown
handlers. Use one or the other, not both.You can store arbitrary extra state on the application instance, using the
+generic app.state
attribute.
For example:
+app.state.ADMIN_EMAIL = 'admin@example.org'
+
Where a request
is available (i.e. endpoints and middleware), the app is available on request.app
.
{"use strict";/*!
+ * escape-html
+ * Copyright(c) 2012-2013 TJ Holowaychuk
+ * Copyright(c) 2015 Andreas Lubbe
+ * Copyright(c) 2015 Tiancheng "Timothy" Gu
+ * MIT Licensed
+ */var Ha=/["'&<>]/;Un.exports=$a;function $a(e){var t=""+e,r=Ha.exec(t);if(!r)return t;var o,n="",i=0,s=0;for(i=r.index;i