Format.
This commit is contained in:
parent
b56371994f
commit
dae877113c
@ -1,9 +1,10 @@
|
|||||||
from app.app import Application as BaseApplication
|
|
||||||
import pathlib
|
import pathlib
|
||||||
|
|
||||||
from aiohttp import web
|
from aiohttp import web
|
||||||
|
from app.app import Application as BaseApplication
|
||||||
|
|
||||||
from snek.system.markdown import MarkdownExtension
|
from snek.system.markdown import MarkdownExtension
|
||||||
|
|
||||||
from snek.system.markdown import render_markdown
|
|
||||||
|
|
||||||
class Application(BaseApplication):
|
class Application(BaseApplication):
|
||||||
|
|
||||||
@ -17,17 +18,26 @@ class Application(BaseApplication):
|
|||||||
self.router.add_get("/{tail:.*}", self.handle_document)
|
self.router.add_get("/{tail:.*}", self.handle_document)
|
||||||
|
|
||||||
async def handle_document(self, request):
|
async def handle_document(self, request):
|
||||||
relative_path = request.match_info['tail'].strip("/")
|
relative_path = request.match_info["tail"].strip("/")
|
||||||
if relative_path == '':
|
if relative_path == "":
|
||||||
relative_path = 'index.html'
|
relative_path = "index.html"
|
||||||
document_path = self.path.joinpath(relative_path)
|
document_path = self.path.joinpath(relative_path)
|
||||||
if not document_path.exists():
|
if not document_path.exists():
|
||||||
return web.Response(status=404,body=b'Resource is not found on this server.',content_type="text/plain")
|
return web.Response(
|
||||||
|
status=404,
|
||||||
|
body=b"Resource is not found on this server.",
|
||||||
|
content_type="text/plain",
|
||||||
|
)
|
||||||
if document_path.is_dir():
|
if document_path.is_dir():
|
||||||
document_path = document_path.joinpath("index.html")
|
document_path = document_path.joinpath("index.html")
|
||||||
if not document_path.exists():
|
if not document_path.exists():
|
||||||
return web.Response(status=404,body=b'Resource is not found on this server.',content_type="text/plain")
|
return web.Response(
|
||||||
|
status=404,
|
||||||
|
body=b"Resource is not found on this server.",
|
||||||
|
content_type="text/plain",
|
||||||
|
)
|
||||||
|
|
||||||
response = await self.render_template(str(document_path.relative_to(self.path)),request)
|
response = await self.render_template(
|
||||||
|
str(document_path.relative_to(self.path)), request
|
||||||
|
)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user