Flask: Difference between revisions
Content added Content deleted
No edit summary |
No edit summary |
||
Line 23: | Line 23: | ||
Access URL over network with custom port: |
Access URL over network with custom port: |
||
app.run(host = '0.0.0.0',port=5005) |
app.run(host = '0.0.0.0',port=5005) |
||
= Uploader Project = |
|||
<syntaxhighlight lang="python"> |
|||
from flask import Flask, render_template, request |
|||
from werkzeug import secure_filename |
|||
app = Flask(__name__) |
|||
@app.route('/upload') |
|||
def upload_file(): |
|||
return render_template('upload.html') |
|||
@app.route('/uploader', methods = ['GET', 'POST']) |
|||
def upload_file(): |
|||
if request.method == 'POST': |
|||
f = request.files['file'] |
|||
f.save(secure_filename(f.filename)) |
|||
return 'file uploaded successfully' |
|||
if __name__ == '__main__': |
|||
app.run(debug = True) |
|||
</syntaxhighlight> |
|||
mkdir templates |
|||
nano upload.html |
|||
<syntaxhighlight lang="html"> |
|||
<html> |
|||
<body> |
|||
<form action = "http://10.10.10.1:5000/uploader" method = "POST" |
|||
enctype = "multipart/form-data"> |
|||
<input type = "file" name = "file" /> |
|||
<input type = "submit"/> |
|||
</form> |
|||
</body> |
|||
</html> |
|||
</syntaxhighlight> |
|||
http://10.10.10.1:5000/upload |