diff --git a/app.py b/app.py index 82638ea..cfb5629 100644 --- a/app.py +++ b/app.py @@ -3,17 +3,20 @@ app = Flask(__name__) + # default page @app.route('/') def index(): return render_template('index.html') + # render home page @app.route('/home') def home(): """ Reder home page """ return render_template('index.html') + # render about page @app.route('/about') def about(): @@ -37,5 +40,27 @@ def language(): return render_template('index.html', questions=questions, language=language) + +@app.route('/problem/') +def problem_solution(filename): + """ + Read the solution code from the file and return the problem_solution.html page to show the solution code to user + """ + # get the language which is passed as a parameter from the index.html + language = request.args.get('language') + + if not language: + return "Language not specified. Please select a language." # Error Message if no Language is selected + + file_path = f"{language}/{filename}" # Filepath + + with open(file_path, 'r') as f: + code = f.read() + + question_name = filename.replace('_', ' ').replace('.cpp', '').replace('.java', '').replace('.py', '') + + return render_template('problem_solution.html', code=code, question_name=question_name) + + if __name__ == '__main__': - app.run() \ No newline at end of file + app.run(debug=True) \ No newline at end of file diff --git a/templates/about.html b/templates/about.html index 4bbc334..7818013 100644 --- a/templates/about.html +++ b/templates/about.html @@ -3,7 +3,7 @@ - DSAmplify - Contribute + DSAmplify - About + + +
+
+

DSAmplify

+
+ +
+ +

{{ question_name }}

+
{{ code }}
+ + + \ No newline at end of file