This file is called 'html app.py'
from flask import Flask, render_template, request
import yfinance as yf
import seaborn as sns
import matplotlib.pyplot as plt
import io
import base64
app = Flask(__name__)
@app.route('/')
def welcome():
return render_template("signInor Login.html")
@app.route('/submit', methods=["POST"] )
def submit():
username = request.form.get('username')
password = request.form.get('password')
if username== "rashmip_21" and password=='fabulousRashmi':
return render_template("home.html")
else:
return "Invalid Credenials"
#@app.route('/goToSMA', methods = ["POST"])
#def gotosma():
# return render_template("Simple Moving Average.html")
@app.route('/sma', methods=["POST"] )
def sma():
ticker_symbol = request.form.get('tickersym')
start_date = request.form.get('start')
end_date = request.form.get('end')
wind_td = request.form.get('windtd')
df=yf.download(ticker_symbol)
df['Simple Moving Average']= df['Close'].rolling(window=wind_td).mean()
sns.lineplot(x='Date',y='Close',data=df.droplevel(1,axis=1),label="Close")
sns.lineplot(x='Date',y='Simple Moving Average',data=df.droplevel(1,axis=1),label="S.M.A.")
plt.xlabel("Date")
plt.ylabel("Average/Close")
app.run(debug=True)
This is 'home.html'
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vizly.welcome</title>
</head>
<link rel="stylesheet" type="text/css" href="{{url_for('static',filename='styles/styleHome.css')}}">
<body id="bodyWelcome" style="background-color: #b8e0fc;">
<nav class="navbar">
<ul>
<img src="{{url_for('static',filename='styles/logo.png')}}" id="logo">
<li><a href="">About Us</a></li>
<li><a href="">Sign In / Login</a></li>
<li><!--<a href="">Stock Data</a>-->
<div class="drop">
<button class="dropbtn">Stock Data</button>
<!--<a href="">Visualize</a>-->
<div class="drop-down">
<a href="">Ticker Symbol</a>
<a href="">Simple Moving Average</a>
<a href="">Exponential Moving Average</a>
</div>
</div>
</li>
<li>
<div class="drop">
<button class="dropbtn">Visualize</button>
<!--<a href="">Visualize</a>-->
<div class="drop-down">
<a href="">Simple Moving Average</a>
<a href="">Exponential Moving Average</a>
<a href="">Bollinger's Band</a>
<a href="">Candlestick Graph</a>
</div>
</div>
</li>
<li><a href="">Home</a></li>
</ul>
</nav>
<p>Do you want to calculate the Simple Moving Average or the Exponential moving average for some historical data? All you need to do is enter the Ticker symbol, the start and end dates and the number of trading days.</p>
<div class="flex-container">
<div class="flex-box"><a href="">Simple Moving Average</a></div>
<div class="flex-box"><a href="">Exponential Moving Average</a></div>
</div>
<p>Or do you want to visualize the Simple Moving Average, Exponential Moving Average, Bollinger's Band or Candlestick chart? Again all you need to do is enter the Ticker symbol, the start and end dates and the number of trading days.</p>
<div class="flex-container">
<div class="flex-box" ><a href="Simple Moving Average.html">SMA Visualizer</a></div>
<div class="flex-box"><a href="">EMA Visualizer</a></div>
<div class="flex-box"><a href="">Bollinger's Band Visualizer</a></div>
<div class="flex-box"><a href="">Candlestick Chart</a></div>
</div>
</body>
</html>
This is welcome.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vizly.welcome</title>
</head>
<link rel="stylesheet" type="text/css" href="{{url_for('static',filename='styles/styleWelcome.css')}}">
<body id="bodyWelcome" style="background-color: #b8e0fc;">
<nav class="navbar">
<ul>
<img src="{{url_for('static',filename='styles/logo.png')}}" id="logo">
<li><a href="">About Us</a></li>
<li><a href="">Sign In / Login</a></li>
<li><!--<a href="">Stock Data</a>-->
<div class="drop">
<button class="dropbtn">Stock Data</button>
<!--<a href="">Visualize</a>-->
<div class="drop-down">
<a href="">Ticker Symbol</a>
<a href="">Simple Moving Average</a>
<a href="">Exponential Moving Average</a>
</div>
</div>
</li>
<li>
<div class="drop">
<button class="dropbtn">Visualize</button>
<!--<a href="">Visualize</a>-->
<div class="drop-down">
<a href="">Simple Moving Average</a>
<a href="">Exponential Moving Average</a>
<a href="">Bollinger's Band</a>
<a href="">Candlestick Graph</a>
</div>
</div>
</li>
<li><a href="home.html">Home</a></li>
</ul>
</nav>
<h1>Welcome to Vizly!</h1>
<h5>Analyze, Visualize, Understand.</h5>
<p>Welcome to Vizly - the Stock Market Visualizer! This tool provides insightful analysis and visualization of
historical stock data, helping you understand market trends and make informed decisions.</p>
<p>Leverage the power of data to explore stock performance. Input any ticker symbol and date range to generate
detailed charts and key financial indicators.</p>
</body>
</html>
This is Simple Moving Average.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="module" src="https://pyscript.net/releases/2024.2.1/core.js"></script>
<link rel="stylesheet" href="https://pyscript.net/releases/2025.7.3/core.css" />
<title>Simple Moving Average</title>
</head>
<link rel="stylesheet" type="text/css" href="{{url_for('static',filename='styles/styleSMA.css')}}">
<body id="bodyWelcome" style="background-color: #b8e0fc;">
<nav class="navbar">
<ul>
<img src="{{url_for('static',filename='styles/logo.png')}}" id="logo">
<li><a href="">About Us</a></li>
<li><a href="">Sign In / Login</a></li>
<li><!--<a href="">Stock Data</a>-->
<div class="drop">
<button class="dropbtn">Stock Data</button>
<!--<a href="">Visualize</a>-->
<div class="drop-down">
<a href="">Ticker Symbol</a>
<a href="">Simple Moving Average</a>
<a href="">Exponential Moving Average</a>
</div>
</div>
</li>
<li>
<div class="drop">
<button class="dropbtn">Visualize</button>
<!--<a href="">Visualize</a>-->
<div class="drop-down">
<a href="">Simple Moving Average</a>
<a href="">Exponential Moving Average</a>
<a href="">Bollinger's Band</a>
<a href="">Candlestick Graph</a>
</div>
</div>
</li>
<li><a href="">Home</a></li>
</ul>
</nav>
<form method="POST" action="/sma">
<label for="tickersym">Enter ticker symbol:</label>
<input type="text" name="tickersym" id="tickersym">
<br>
<label for="start"> Enter start date:</label>
<input type="date" name="start" id="start"><br>
<label for="end">Enter end date:</label>
<input type="date" name="end" id="end"><br>
<label for="windtd">Enter number of trading days (window) for SMA:</label>
<input type="number" name="windtd" id="windtd"><br>
<button type="button" name="calculate" id="calculate">Calculate SMA</button>
<button type="button" name="refresh" id="refresh">Refresh</button>
</form>
</body>
</html>
I want the user to input the ticker symbol, start date, end date, and window to the website. Then I want to fetch the historical stock data from yfinance and plot the SMA graph using seaborn and matplotlib. However, I am neither able to go to the 'simple moving average' page from the 'home' page, nor am I able to return the graph to the website. Please help. I have used the necessary CSS.
404?