Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,38 @@
from flask import Flask
from flask import render_template, request
from datetime import datetime
import os
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = 'tmp/'


@app.route('/')
def homepage():
the_time = datetime.now().strftime("%A, %d %b %Y %l:%M %p")

return """
<h1>Hello heroku</h1>
<p>It is currently {time}.</p>
<html>
<body>
<form action = "/uploader" method = "POST"
enctype = "multipart/form-data">
<input type = "file" name = "file" />
<input type = "submit"/>
</form>
</body>
</html>
"""

@app.route('/uploader', methods = ['GET', 'POST'])
def upload_file():
if request.method == 'POST':
mypath = os.getcwd()+'/tmp/'
if not os.path.isdir(mypath):
os.mkdir(mypath)
f = request.files['file']
f.save(os.path.join(app.config['UPLOAD_FOLDER'],f.filename))
if os.path.exists(os.path.join(app.config['UPLOAD_FOLDER'], f.filename)):
return 'file uploaded successfully'
else:
return 'file upload fail'

<img src="http://loremflickr.com/600/400" />
""".format(time=the_time)

if __name__ == '__main__':
app.run(debug=True, use_reloader=True)
Expand Down
2 changes: 1 addition & 1 deletion runtime.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
python-3.5.1
python-3.6.8