Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 19024

Can't open a new html page by clicking on an image [flask/html/python]

$
0
0

I got a simple flask server that manages a login page.The webpage works fine: login, logout, register, etcAfter the login page there is a "home.html" page with 3 images. What I'm trying to do is to open a second webpage by clicking on the image.The page I'm trying to load is called "output.html" and it is inside the folder "templates"

Folder structure:

  • webserver

    • instance
    • website
      • images
      • static
      • templates
        • base.html
        • home.html
        • login.html
        • main.html
        • output.html
        • sign_up.html
  • init.py

  • auth.py

  • models.py

Flask script:

from flask import Flask, render_template, url_for, redirect, send_from_directory, requestfrom flask_login import UserMixin, login_user, LoginManager, login_required, logout_user, current_userfrom flask_wtf import FlaskFormfrom wtforms import StringField, PasswordField, SubmitFieldfrom wtforms.validators import InputRequired, Length, ValidationErrorapp = create_app()#app = Flask(__name__, template_folder='templates')app.config['SECRET_KEY'] = 'thisisasecretkey'login_manager = LoginManager()login_manager.init_app(app)login_manager.login_view = 'login'class RegisterForm(FlaskForm):    username = StringField(validators=[                           InputRequired(), Length(min=4, max=20)], render_kw={"placeholder": "Username"})    password = PasswordField(validators=[                             InputRequired(), Length(min=8, max=20)], render_kw={"placeholder": "Password"})    submit = SubmitField('Register')class LoginForm(FlaskForm):    username = StringField(validators=[                           InputRequired(), Length(min=4, max=20)], render_kw={"placeholder": "Username"})    password = PasswordField(validators=[                             InputRequired(), Length(min=8, max=20)], render_kw={"placeholder": "Password"})    submit = SubmitField('Login')#@app.route("/images/<path:filename>")#def serve_image(filename):#    return send_from_directory("images", filename)@app.route('/')def index():    return render_template('home.html')@app.route('/output', methods=['GET', 'POST'])def output():    return render_template('output.html')@app.route('/login', methods=['GET', 'POST'])def login():    form = LoginForm()    return render_template('login.html', form=form)@app.route('/dashboard', methods=['GET', 'POST'])@login_requireddef dashboard():    return render_template('dashboard.html')@app.route('/logout', methods=['GET', 'POST'])@login_requireddef logout():    logout_user()    return redirect(url_for('login'))@app.route('/register', methods=['GET', 'POST'])def register():    form = RegisterForm()    return render_template('register.html', form=form)if __name__ == '__main__':    #app.run()    app.run()

HTML side:

<div id="Ohm" class="tabcontent"><h3>Escolha um dos três circuitos</h3><p>Clique OK para seguir</p><div><img         src="../images/circuit_R1.png"         width="30%"         height="auto"         alt="circuito R1"         class="responsive"         onclick="redirecionarPaginaEAcionar('10010101', '/output')"         style="cursor: pointer;" ><img           src="../images/circuit_R2.png"           width="30%"           height="auto"           alt="circuito R1"           class="responsive"           onclick="accionarReles('01011011')"           style="cursor: pointer;" >(...)<script>    function accionarReles(parametro)      {     (...)    }    function redirecionarPaginaEAcionar(parametro, url) {      accionarReles(parametro); // Chama a função accionarReles com o parâmetro especificado      window.location.href = url; // Redireciona para a URL especificada    }</script>

So, after I run the server and login, the script calls home.html.When click in the image another html page should be open: output.html.However, as the program is I get an 404 error page not found.

But, if I replace output with login, which is a page that is in the same folder, everything is right.

I can't find the error/mistake and I can't open another page unless is "home.html"So, I need some help to find the mistake


Viewing all articles
Browse latest Browse all 19024

Trending Articles