diff --git a/examples/subapps/README.md b/examples/subapps/README.md new file mode 100644 index 0000000..e9902bb --- /dev/null +++ b/examples/subapps/README.md @@ -0,0 +1 @@ +This directory contains examples that demonstrate sub-applications. diff --git a/examples/subapps/app.py b/examples/subapps/app.py new file mode 100644 index 0000000..29f8615 --- /dev/null +++ b/examples/subapps/app.py @@ -0,0 +1,27 @@ +from microdot import Microdot +from subapp import subapp + +app = Microdot() +app.mount(subapp, url_prefix='/subapp') + + +@app.route('/') +async def hello(request): + return ''' + + + + Microdot Sub-App Example + + + +
+

Microdot Main Page

+

Visit the sub-app.

+
+ + + ''', 200, {'Content-Type': 'text/html'} + + +app.run(debug=True) diff --git a/examples/subapps/subapp.py b/examples/subapps/subapp.py new file mode 100644 index 0000000..8507446 --- /dev/null +++ b/examples/subapps/subapp.py @@ -0,0 +1,44 @@ +from microdot import Microdot + +subapp = Microdot() + + +@subapp.route('') +async def hello(request): + # request.url_prefix can be used in links that are relative to this subapp + return f''' + + + + Microdot Sub-App Example + + + +
+

Microdot Sub-App Main Page

+

Visit the sub-app's secondary page.

+

Go back to the app's main page.

+
+ + + ''', 200, {'Content-Type': 'text/html'} + + +@subapp.route('/second') +async def second(request): + return f''' + + + + Microdot Sub-App Example + + + +
+

Microdot Sub-App Secondary Page

+

Visit the sub-app's main page.

+

Go back to the app's main page.

+
+ + + ''', 200, {'Content-Type': 'text/html'}