<!DOCTYPE html> <html lang="ru"> <head> <meta charset="UTF-8"> <title>{{ title }}</title> <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='normalize.css') }}"> <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='codehilite.css') }}"> <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}"> </head> <body> <table> <tr> <td valign="top" class="side"> <h1 class="logo"> <a href="/">{{ title }}</a> </h1> {{ side|safe }} </td> <td valign="top"> {{ content|safe }} </td> </tr> </table> </body> </html>
# [app_setting] # start_page=start # side_bar=sidebar # md pages_folder=pages # port=8000 # not_found_text= # main_title=
class ConfigProvider: config_file_name = 'config.ini' start_page = 'start' side_bar = 'sidebar' pages_folder = 'pages' port = '8080' not_found_text = 'Page Not Found' main_title = u' ' def __init__(self): # if function.check_found_file(self.config_file_name): config = ConfigParser.RawConfigParser() config.read(self.config_file_name) # self.start_page = config.get('app_setting', 'start_page').decode('utf8') self.side_bar = config.get('app_setting', 'side_bar').decode('utf8') self.pages_folder = config.get('app_setting', 'pages_folder').decode('utf8') self.port = config.getint('app_setting', 'port') self.not_found_text = config.get('app_setting', 'not_found_text').decode('utf8') self.main_title = config.get('app_setting', 'main_title').decode('utf8')
def check_found_file(filename): """ """ try: file = open(filename) except IOError as e: return False else: with file: return True
def markdown_to_html(filename): """ markdown html """ f = open(config.pages_folder + '/' + filename + '.md', 'r') all_file = '' for st in f.readlines(): all_file += st html = markdown.markdown(all_file.decode('utf8'), extensions=['codehilite']) return html
# def get_page(name): # if function.check_found_file(config.pages_folder + '/' + name + '.md'): page = function.markdown_to_html(name) else: page = config.not_found_text return page
@app.route('/') def hello(): return render_template( 'page.html', title=config.main_title, side=get_page(config.side_bar), content=get_page(config.start_page) ) @app.route('/<name>') def page(name): return render_template( 'page.html', title=config.main_title, side=get_page(config.side_bar), content=get_page(name) ) if __name__ == '__main__': app.run(port=config.port)
Source: https://habr.com/ru/post/307318/
All Articles