-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
74 lines (49 loc) · 1.26 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
68
69
70
71
72
73
74
from flask import Flask, render_template, request, make_response, redirect, url_for
app = Flask(
__name__,
template_folder='templates',
static_folder='static'
)
# Index page and Rendering Basic Templates
@app.route('/')
def index():
return render_template('index.html')
# Creating different routes
@app.route('/second')
def second():
return "I'm on a separate route"
# HTTP Methods
@app.route('/requesthttp', methods=['GET', 'POST'])
def requesthttp():
if request.method == 'POST':
return "Auth here"
else:
return "Ask for creds here"
# File Uploads (needs an HTML Form)
@app.route('/upload', methods=['GET', 'POST'])
def upload_file():
if request.method == 'GET':
file = request.files['filename']
file.save('uploads/upload.txt')
# Reading Cookies 🍪
@app.route('/readcookie')
def readcookie():
cookie = request.cookies.get('cookie')
return cookie
# Storing Cookies
@app.route('/storecookie')
def storecookie():
response = make_response(render_template(index.html))
response.set_cookie('cookie', 'whatever')
return response
# Redirects
@app.route('/redirect')
def redirec():
return redirect(url_for('index'))
if __name__ == '__main__':
# Run the Flask app
app.run(
host='0.0.0.0',
debug=True,
port=8080
)