Change main.py to app.py to run simply with "flask run". Add a demo of internal linking
[wiki] / app.py
1 import commonmark
2 import flask
3
4 app = flask.Flask(__name__)
5
6 @app.route('/')
7 def index():
8     return 'Hello, world'
9
10 @app.route('/p/<name>')
11 def page(name):
12     for ch in name:
13         if not ch in 'abcdefghijklmnopqrstuvwxyz_0123456789':
14             flask.abort(404)
15
16     try:
17         with open('pages/{}.md'.format(name), 'r') as f:
18             content = commonmark.commonmark(f.read())
19     except FileNotFoundError as e:
20         flask.abort(404)
21
22     title = name.replace('_', ' ').title()
23
24     return flask.render_template('page.html', content=content, title=title)
25
26