Sa-m commited on
Commit
950f217
1 Parent(s): e3a53b9

Update server.py

Browse files
Files changed (1) hide show
  1. server.py +35 -2
server.py CHANGED
@@ -8,10 +8,10 @@ import requests
8
  app = Flask(__name__)
9
  CORS(app)
10
 
11
- @app.route('/')
12
  def welc():
13
  return 'Main page '
14
-
15
  # @app.route('/fail/<int:marks>')
16
  # def fail(score):
17
  # return 'failure'
@@ -29,6 +29,39 @@ def results(marks):
29
  result='fail'
30
  return f'{result} with {marks} marks'
31
  # return redirect(url_for(result,score=marks))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
  if __name__ == "__main__":
34
  app.run(host="0.0.0.0", port=7860)
 
8
  app = Flask(__name__)
9
  CORS(app)
10
 
11
+ '''@app.route('/')
12
  def welc():
13
  return 'Main page '
14
+ '''
15
  # @app.route('/fail/<int:marks>')
16
  # def fail(score):
17
  # return 'failure'
 
29
  result='fail'
30
  return f'{result} with {marks} marks'
31
  # return redirect(url_for(result,score=marks))
32
+
33
+ def allowed_file(filename):
34
+ return '.' in filename and \
35
+ filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
36
+
37
+
38
+ @app.route('/', methods=['GET', 'POST'])
39
+ def upload_file():
40
+ if request.method == 'POST':
41
+ # check if the post request has the file part
42
+ if 'file' not in request.files:
43
+ flash('No file part')
44
+ return redirect(request.url)
45
+ file = request.files['file']
46
+ # if user does not select file, browser also
47
+ # submit an empty part without filename
48
+ if file.filename == '':
49
+ flash('No selected file')
50
+ return redirect(request.url)
51
+ if file and allowed_file(file.filename):
52
+ filename = secure_filename(file.filename)
53
+ file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
54
+ return redirect(url_for('uploaded_file',
55
+ filename=filename))
56
+ return '''
57
+ <!doctype html>
58
+ <title>Upload new File</title>
59
+ <h1>Upload new File</h1>
60
+ <form method=post enctype=multipart/form-data>
61
+ <input type=file name=file>
62
+ <input type=submit value=Upload>
63
+ </form>
64
+ '''
65
 
66
  if __name__ == "__main__":
67
  app.run(host="0.0.0.0", port=7860)