-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.py
66 lines (55 loc) · 1.71 KB
/
index.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
from flask import Flask
from flask import request
from flask import render_template
import os
app = Flask(__name__)
@app.route("/")
def hello():
app.logger.debug('A value for debugging')
random = os.urandom(24)
return random
@app.route("/login", methods=['POST', 'GET'])
def login():
error = None
if request.method == 'POST':
if request.form['username'] == 'jack':
error = 'valid username/password'
return log_the_user_in(request.form['username'])
else:
error = 'Invalid username/password'
# the code below is executed if the request method
# was GET or the credentials were invalid
return render_template('login.html', error=error)
@app.route('/user/<username>')
def show_user_profile(username):
# show the user profile for that user
return 'User %s' % username
@app.route('/post/<int:post_id>')
def show_post(post_id):
# show the post with the given id, the id is an integer
return 'Post %d' % post_id
@app.route('/multi',methods=['GET','POST'])
def multiRequest():
if request.method == 'GET':
return 'this is get'
else:
return 'this is post'
@app.route('/render')
@app.route('/render/<name>')
def renderPage(name=None):
return render_template('index.html',name=name)
@app.route('/upload', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
f = request.files['the_file']
f.save('/var/www/uploads/uploaded_file.txt')
@app.errorhandler(404)
def not_found(error):
return render_template('error.html'), 404
def valid_login(name,password):
return 1==1
def log_the_user_in(name):
app.logger.debug(name)
return name
if __name__ == "__main__":
app.run()