Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Oct 27, 2024. It is now read-only.

Commit a414d22

Browse files
Merge pull request #157 from baranwalayush/main
Add app.py
2 parents c53dc21 + eca71d5 commit a414d22

File tree

3 files changed

+58
-5
lines changed

3 files changed

+58
-5
lines changed

‎app.py‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from flask import Flask, render_template, request
2+
import os
3+
4+
app = Flask(__name__)
5+
6+
# default page
7+
@app.route('/')
8+
def index():
9+
return render_template('index.html')
10+
11+
# render home page
12+
@app.route('/home')
13+
def home():
14+
""" Reder home page """
15+
return render_template('index.html')
16+
17+
# render about page
18+
@app.route('/about')
19+
def about():
20+
""" Render about page"""
21+
return render_template('about.html')
22+
23+
24+
@app.route('/language', methods=['POST'])
25+
def language():
26+
"""
27+
Fetch question name and file path based on the selected language and returns the home page with the questions information
28+
"""
29+
language = request.form['language']
30+
solutions_dir = f"{language}/"
31+
32+
questions = [] # list to store the information related to question
33+
for filename in os.listdir(solutions_dir):
34+
# question name would not contain underscore and extension
35+
question_name = filename.replace('_', ' ').replace('.cpp', '').replace('.java', '').replace('.py', '')
36+
questions.append({'name': question_name, 'file': filename})
37+
38+
return render_template('index.html', questions=questions, language=language)
39+
40+
if __name__ == '__main__':
41+
app.run()

‎templates/about.html‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,11 @@
111111
<header>
112112
<div class="Head-Name">
113113
<p>DSAmplify</p>
114+
<h4>Make your DSA journey easier with us</h4>
114115
</div>
115116
<ul>
116-
<li><a href="index.html">Home</a></li>
117-
<li><a href="about.html">About</a></li>
117+
<li><a href="home">Home</a></li>
118+
<li><a href="about">About</a></li>
118119
<li><a href="#">Contributors</a></li>
119120
<li><a href="#">Contact</a></li>
120121
</ul>

‎templates/index.html‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6-
<title>DSAmplify - Contribute</title>
6+
<title>DSAmplify</title>
77

88
<style>
99
body {
@@ -111,10 +111,11 @@
111111
<header>
112112
<div class="Head-Name">
113113
<p>DSAmplify</p>
114+
<h4>Make your DSA journey easier with us</h4>
114115
</div>
115116
<ul>
116-
<li><a href="index.html">Home</a></li>
117-
<li><a href="about.html">About</a></li>
117+
<li><a href="home">Home</a></li>
118+
<li><a href="about">About</a></li>
118119
<li><a href="#">Contributors</a></li>
119120
<li><a href="#">Contact</a></li>
120121
</ul>
@@ -131,5 +132,15 @@ <h1>DSA Problem Solutions</h1>
131132
<input type="submit" value="Submit">
132133
</form>
133134

135+
<!-- display the questions of the selected language -->
136+
{% if questions %}
137+
<h2>{{ language }} Problems</h2>
138+
<ul>
139+
{% for question in questions %}
140+
<li><a href="#">{{ question['name'] }}</a></li>
141+
{% endfor %}
142+
</ul>
143+
{% endif %}
144+
134145
</body>
135146
</html>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /