skip to Main Content

main.py

`from flask import Flask, render_template

app = Flask(__name__)


@app.route('/')
def home():
    return render_template('home.html')`

home.html

`<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
  <h1>HOME</h1>
  <a href="hello.html">hello</a>
</body>
</html>`

hello.html

`<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>hello</title>
</head>
<body>
    <h1>Hello</h1>
</body>
</html>`

home.html is displaying while clicking the address
hello.html is not displaying while clicking the hyper link

2

Answers


  1. Try this code

    In main.py: Created new @app.route(‘/hi’) that returns hello.html when called from home.html (see below)

    In home.html: Changed href="hello.html" To href="/hi" to call that Flask route:

    Flask Code:

    from flask import Flask, render_template
    
    
    app = Flask(__name__)
    
    
    @app.route('/')
    def home():
        return render_template('home.html')
    
    @app.route('/hi')
    def hi_there():
        return render_template('hello.html')
    
    
    app.run()
    

    home.html:

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Title</title>
    </head>
    <body>
      <h1>HOME</h1>
      <a href="/hi">hello</a>
    </body>
    </html>
    

    hello.html:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>hello</title>
    </head>
    <body>
        <h1>Hello</h1>
    </body>
    </html>
    
    Login or Signup to reply.
  2. It looks like you’re missing a route in your main.py file for the hello.html page. You need to add a new route that maps to the URL path /hello.html and returns the hello.html template.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search