-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhello.py
More file actions
60 lines (45 loc) · 1.24 KB
/
hello.py
File metadata and controls
60 lines (45 loc) · 1.24 KB
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
__title__ = ''
__author__ = 'wang'
__mtime__ = '2016/7/11'
"""
from flask import Flask,render_template
from flask_bootstrap import Bootstrap
from flask_wtf import Form
from wtforms import StringField,SubmitField
from wtforms.validators import Required
#from flask_moment import Moment
#from datetime import datetime
class NameFrom(Form):
name = StringField('What is your name?',validators=[Required()])
submit = SubmitField('submit')
app = Flask(__name__)
app.config['SECRET_KEY'] = 'ni cai'
bootstrap = Bootstrap(app)
#moment = Moment(app)
'''
@app.route('/')
def index():
return render_template('index.html',current_time=datetime.utcnow())
'''
@app.route('/',methods=['GET','POST'])
def index():
name = None
nameForm= NameFrom()
if nameForm.validate_on_submit():
name = nameForm.name.data
nameForm.name.data = ''
return render_template('index.html',form=nameForm,name= name)
@app.route('/user/<name>')
def user(name):
return render_template('user.html',name=name)
@app.errorhandler(404)
def page_not_found(e):
return render_template('404.html'),404
@app.errorhandler(500)
def internal_server_error(e):
return render_template('500.html'),505
if __name__ == '__main__':
app.run(debug=True)