Sa-m's picture
Update server.py
950f217
raw
history blame
1.91 kB
from flask import Flask,redirect,url_for
from flask import Flask, jsonify, render_template, request, stream_with_context, Response
from flask_cors import CORS
import requests
app = Flask(__name__)
CORS(app)
'''@app.route('/')
def welc():
return 'Main page '
'''
# @app.route('/fail/<int:marks>')
# def fail(score):
# return 'failure'
# @app.route('/success/<int:marks>')
# def success(score):
# return 'success'
@app.route('/results/<int:marks>')
def results(marks):
if marks>36:
result='Passed'
else:
result='fail'
return f'{result} with {marks} marks'
# return redirect(url_for(result,score=marks))
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
@app.route('/', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
# check if the post request has the file part
if 'file' not in request.files:
flash('No file part')
return redirect(request.url)
file = request.files['file']
# if user does not select file, browser also
# submit an empty part without filename
if file.filename == '':
flash('No selected file')
return redirect(request.url)
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
return redirect(url_for('uploaded_file',
filename=filename))
return '''
<!doctype html>
<title>Upload new File</title>
<h1>Upload new File</h1>
<form method=post enctype=multipart/form-data>
<input type=file name=file>
<input type=submit value=Upload>
</form>
'''
if __name__ == "__main__":
app.run(host="0.0.0.0", port=7860)