Simple file-based wiki with fulltext-search.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.7 KiB

7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
  1. import os
  2. from flask import Flask, flash, make_response, render_template, request, redirect, abort
  3. import content as cont
  4. import config
  5. import search as src
  6. from forms import SearchForm, csrf
  7. app = Flask(__name__)
  8. SECRET_KEY = os.urandom(32)
  9. app.secret_key = SECRET_KEY
  10. csrf.init_app(app)
  11. TITLE = config.TITLE
  12. STYLE = config.STYLE
  13. @app.errorhandler(404)
  14. def page_not_found(e):
  15. return render_template('error.html', title=TITLE, errorcode='404', style=STYLE), 404
  16. @app.route('/')
  17. @app.route('/index.html')
  18. def index():
  19. return render_template('index.html', title=TITLE, style=STYLE), 200
  20. @app.route('/search', methods=['GET', 'POST'])
  21. @app.route('/search.html', methods=['GET', 'POST'])
  22. def search():
  23. form = SearchForm()
  24. if request.method == 'POST':
  25. query_str = request.form['query_str']
  26. content = cont.gen_query_res_string(query_str)
  27. return render_template('search.html', title=TITLE, style=STYLE, form=form, content=content), 200
  28. return render_template('search.html', title=TITLE, style=STYLE, form=form, content=''), 200
  29. @app.route('/entry/<path:fullurl>')
  30. def entry(fullurl):
  31. content = cont.gen_stand_string(fullurl)
  32. return render_template('entry.html', title=TITLE, style=STYLE, content=content), 200
  33. @app.route('/namespace/', defaults={'fullurl': ''})
  34. @app.route('/namespace/<path:fullurl>')
  35. def namespace(fullurl=''):
  36. content = cont.gen_arch_string(fullurl)
  37. if content == None:
  38. return render_template('error.html', title=TITLE, errorcode='404', style=STYLE), 404
  39. return render_template('entry.html', title=TITLE, style=STYLE, content=content), 200
  40. if __name__ == '__main__':
  41. app.run(host='0.0.0.0')