forked from chenrl129/InternationalStudentsPage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
45 lines (29 loc) · 1.04 KB
/
app.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
# import necessary libraries
from flask import Flask, render_template, url_for, jsonify, current_app
from students import students
# create Flask app
app = Flask(__name__)
# Read the article function
def read_article(filename):
with open(filename, 'r', encoding='utf-8') as f:
content = f.read()
paragraphs = content.strip().split('\n') # split text into paragraphs using two newline characters as a delimiter
return paragraphs
# Updated main
# define routes
@app.route("/")
def home():
return render_template("home.html", students=students)
@app.route("/students")
def student_list():
return jsonify(students)
@app.route("/student/<int:id>")
def student_detail(id):
student = students[id-1]
article_file = student['article_file']
audio_file = student['audio_file']
paragraphs = read_article(article_file)
return render_template("student_detail.html", student=student, paragraphs=paragraphs, audio_file=audio_file)
# run the app
app.run(host='0.0.0.0', port=3000)
# app.run(debug = True, port=3000)