-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello.py
42 lines (36 loc) · 1.49 KB
/
hello.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
from flask import Flask, render_template, session, redirect, url_for, flash
from flask_bootstrap import Bootstrap
from flask_moment import Moment
#from datetime import datetime
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField
from wtforms.validators import DataRequired
app = Flask(__name__)
bootstrap = Bootstrap(app)
moment = Moment(app)
app.config['SECRET_KEY'] = 'Chave forte'
class NameForm(FlaskForm):
name = StringField('What is your name?', validators = [DataRequired()])
submit = SubmitField('Submit')
@app.route('/', methods=['GET', 'POST'])
def index():
form = NameForm()
if form.validate_on_submit():
old_name = session.get('name')
if old_name is not None and old_name != form.name.data:
flash('Looks like you have changed your name!')
session['name'] = form.name.data
return redirect(url_for('index'))
return render_template('index.html', form=form, name=session.get('name'))
@app.route('/user/<name>/<id>/<institution>')
def user(name, id, institution):
return render_template('user.html', name=name, id=id, institution=institution)
@app.route('/contextorequisicao/<name>')
def contexto_requisicao(name):
user_agent = request.headers.get('User-Agent')
ip = request.remote_addr
host = request.headers.get('Host')
return render_template('contexto.html', name=name, user_agent=user_agent, ip=ip, host=host)
@app.errorhandler(404)
def page_not_found(e):
return render_template('404.html'), 404