-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
40 lines (28 loc) · 877 Bytes
/
app.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
# coding: utf-8
from datetime import datetime
from flask import Flask, redirect, request
from flask import render_template
from flask_sockets import Sockets
from views.todos import todos_view
from forms import VipListForm, make_choice
app = Flask(__name__)
sockets = Sockets(app)
# 动态路由
app.register_blueprint(todos_view, url_prefix='/todos')
@app.route('/', methods=['GET', 'POST'])
def index():
xform = request.form
form = VipListForm(xform)
platforms = make_choice('platformlist')
if form.validate():
new_url = form.parser.data + form.url.data
return redirect(new_url)
return render_template('index.html', form=form, platforms=platforms)
@app.route('/time')
def time():
return str(datetime.now())
@sockets.route('/echo')
def echo_socket(ws):
while True:
message = ws.receive()
ws.send(message)