-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·67 lines (46 loc) · 1.44 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#! /usr/bin/env python3
import os
from flask import Flask, send_from_directory
from flask import render_template, request
from flask.ext.babelex import Babel
app = Flask(__name__)
app.debug = True
babel = Babel(app)
app.config['BABEL_DEFAULT_LOCALE'] = 'en'
@app.route('/favicon.ico')
def favicon():
return send_from_directory(os.path.join(app.root_path, 'static'),
'favicon.ico', mimetype='image/vnd.microsoft.icon')
def selector(language_code=None):
if not language_code or language_code not in ('en', 'pt'):
language_code = 'en'
if language_code == 'pt':
language_code = 'pt_BR'
def get_locale():
return language_code
babel.locale_selector_func = get_locale
@app.route('/')
@app.route('/<lang>/')
def home(lang=None):
selector(lang)
return render_template('home.html', lang=lang)
@app.route('/about/')
@app.route('/about/<lang>/')
def about(lang=None):
selector(lang)
return render_template('about.html', lang=lang)
@app.route('/music/')
@app.route('/music/<lang>/')
def music(lang=None):
selector(lang)
context = {
'STATIC_URL': app.static_url_path,
}
return render_template('music.html', lang=lang, **context)
@app.route('/contact/')
@app.route('/contact/<lang>/')
def contact(lang=None):
selector(lang)
return render_template('contact.html', lang=lang)
if __name__ == '__main__':
app.run('0.0.0.0', port=8001, processes=5)