Files

30 lines
869 B
Python

from flask import Flask, render_template_string
import os
app = Flask(__name__, static_folder='.', static_url_path="/", template_folder="./")
app.debug = True
def render_with_base(html_content):
with open('_base', 'r', encoding='utf-8') as f:
base_template = f.read()
return base_template.replace('{{ MAIN }}', html_content)
@app.route('/')
def index():
with open('index.html', 'r', encoding='utf-8') as f:
content = f.read()
return render_with_base(content)
@app.route('/<file>')
def render_page(file):
if not file.endswith('.html'):
file += '.html'
if os.path.exists(file):
with open(file, 'r', encoding='utf-8') as f:
content = f.read()
return render_with_base(content)
else:
return '404 Not Found', 404
if __name__ == '__main__':
app.run()