Python Forum
help with url links- href links don't work properly
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help with url links- href links don't work properly
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.

from flask import Flask, render_template, url_for

app = Flask(__name__)

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


    df=data.DataReader(name="TSLA", data_source="yahoo", start=start, end=end)

    def inc_dec(c,o):
        if c > o:
        elif c< o:
        return value

    df["Status"]=[inc_dec(c,o) for c, o in zip(df.Close, df.Open)]

    p=figure(x_axis_type='datetime', width=1000, height=300, sizing_mode="scale_width")
    p.title.text="Candlestick Chart"


    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)
    return render_template("plot.html", 

def home():
    return render_template("C:\\Users\\Michael\\OneDrive\\Documents\\VS CODE\\Section_19\\templates\\home.html")

def about():
    return render_template("C:\\Users\\Michael\\OneDrive\\Documents\\VS CODE\\Section_19\\templates\\about.html")

if __name__ == "__main__":
<!DOCTYPE html>
<title>Flask App</title>
<link rel="stylesheet" href="{{url_for('static',filename='css\\main.css')}}">
<div class="container">
<h1 class="logo">Michael's web app</h1>
<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>
<div class="container">
{%block content%}

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.

Possibly Related Threads…
Thread Author Replies Views Last Post
  Why my lambda doesn't work properly? Snake 6 1,294 Mar-29-2020, 04:26 PM
Last Post: Snake
  Having my output links become clickable bigmit37 8 17,113 May-25-2017, 08:17 PM
Last Post: bigmit37
  Removing handles and links from string kiton 2 2,813 May-06-2017, 02:11 PM
Last Post: kiton

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020