index.py 961 B

12345678910111213141516171819202122232425262728293031
  1. from flask import *
  2. from flask_babel import *
  3. app = Flask(__name__)
  4. babel = Babel(app)
  5. app.config.from_object('config')
  6. @babel.localeselector
  7. def get_locale():
  8. return g.get('current_lang', app.config['BABEL_DEFAULT_LOCALE'])
  9. @app.route('/dist')
  10. def dist():
  11. return render_template('distro.html', current_lang = app.config['BABEL_DEFAULT_LOCALE'])
  12. @app.route('/contribute')
  13. def contribute():
  14. return render_template('contribute.html', current_lang = app.config['BABEL_DEFAULT_LOCALE'])
  15. @app.route('/change_language', methods = ['POST', 'GET'])
  16. def change_language():
  17. if request.method == 'POST':
  18. app.config['BABEL_DEFAULT_LOCALE'] = app.config['LANGUAGE'][request.form['lang']]
  19. return redirect(request.referrer)
  20. @app.route('/')
  21. def index():
  22. return render_template('index.html', current_lang = app.config['BABEL_DEFAULT_LOCALE'])
  23. if __name__ == '__main__':
  24. app.run(debug = True, host='0.0.0.0', port=4000)