Jan-05-2021, 06:46 PM
I am having trouble with the links in my code. I had everything running fine, but when I click on the url links (to go to home/about/plot) I get an error 404 message. I have tried a bunch of recommendations but nothing has worked. If I run the individual pages (home/about/plot) I can get to them, but when I try on the site page, the error comes up. I tried changing folders/filepath as well. I just can't seem to get this figured out.
Any insight on what I might be doing wrong? I am using VS Code. I did however try it on another computer using pycharm and I'm still getting the same result. I'm going bonkers trying to figure it out.
<html>
<head>
<title>Flask App</title>
<link rel="stylesheet" href="{{url_for('static',filename='css\\main.css')}}">
</head>
<body>
<header>
<div class="container">
<h1 class="logo">Michael's web app</h1>
<strong><nav>
<ul class="menu">
<li><a href="{{ url_for ('home')}}">Home</a></li>
<li><a href="{{ url_for ('about')}}">About</a></li>
<li><a href="{{ url_for ('plot')}}">Plot</a></li>
</ul>
</nav></strong>
</div>
</header>
<div class="container">
{%block content%}
{%endblock%}
</div>
</body>
</html>
VS%20CODE/Section_19/templates/%7B%7B%20url_for%20('plot')%7D%7D is the end of the url, I think that end url_for might be causing an issue. I don't know how to change that.
Any insight on what I might be doing wrong? I am using VS Code. I did however try it on another computer using pycharm and I'm still getting the same result. I'm going bonkers trying to figure it out.
from flask import Flask, render_template, url_for app = Flask(__name__) @app.route('/plot/') def plot(): from pandas_datareader import data import datetime from bokeh.plotting import figure, show, output_file from bokeh.embed import components from bokeh.resources import CDN start=datetime.datetime(2020,11,1) end=datetime.datetime(2020,12,29) df=data.DataReader(name="TSLA", data_source="yahoo", start=start, end=end) def inc_dec(c,o): if c > o: value="Increase" elif c< o: value="Decrease" else: value="Equal" return value df["Status"]=[inc_dec(c,o) for c, o in zip(df.Close, df.Open)] df["Middle"]=(df.Open+df.Close)/2 df["Height"]=abs(df.Close-df.Open) p=figure(x_axis_type='datetime', width=1000, height=300, sizing_mode="scale_width") p.title.text="Candlestick Chart" p.grid.grid_line_alpha=0.3 hours_12=12*60*60*1000 p.segment(df.index, df.High, df.index, df.Low, color="Black") p.rect(df.index[df.Status=="Increase"], df.Middle[df.Status=="Increase"], hours_12, df.Height[df.Status=="Increase"], fill_color="#32CD32", line_color="black") p.rect(df.index[df.Status=="Decrease"], df.Middle[df.Status=="Decrease"], hours_12, df.Height[df.Status=="Decrease"], fill_color="#FF0000", line_color="black") script1, div1 = components(p) cdn_js=CDN.js_files[0] return render_template("plot.html", web_script=script1, div1=div1, cdn_js=cdn_js) @app.route('/') def home(): return render_template("C:\\Users\\Michael\\OneDrive\\Documents\\VS CODE\\Section_19\\templates\\home.html") @app.route('/about/') def about(): return render_template("C:\\Users\\Michael\\OneDrive\\Documents\\VS CODE\\Section_19\\templates\\about.html") if __name__ == "__main__": app.run(debug=True)<!DOCTYPE html>
<html>
<head>
<title>Flask App</title>
<link rel="stylesheet" href="{{url_for('static',filename='css\\main.css')}}">
</head>
<body>
<header>
<div class="container">
<h1 class="logo">Michael's web app</h1>
<strong><nav>
<ul class="menu">
<li><a href="{{ url_for ('home')}}">Home</a></li>
<li><a href="{{ url_for ('about')}}">About</a></li>
<li><a href="{{ url_for ('plot')}}">Plot</a></li>
</ul>
</nav></strong>
</div>
</header>
<div class="container">
{%block content%}
{%endblock%}
</div>
</body>
</html>
VS%20CODE/Section_19/templates/%7B%7B%20url_for%20('plot')%7D%7D is the end of the url, I think that end url_for might be causing an issue. I don't know how to change that.