[Python] Why does the buy page no longer exist on my website? [closed]

Discussão em 'Python' iniciado por Stack, Agosto 3, 2025.

  1. Stack

    Stack Membro Participativo

    I am no longer able to access the buy page of my website. I just receive an error that the page no longer exists even though it is defined in routes and there is an html template for it. All other pages in my website work and so I am confused why this one doesn't. Image of error on website within buy page

    Below is the code I thought might be relevant to the problem:

    init.py

    from flaskblog.extensions import db, login_manager, bcrypt, mail, migrate, config, Flask

    def create_app(config_class=config):
    app = Flask(__name__)
    app.config.from_object(config_class)

    db.init_app(app)
    migrate.init_app(app, db)
    bcrypt.init_app(app)
    mail.init_app(app)
    login_manager.init_app(app)

    from flaskblog.users.routes import users
    from flaskblog.posts.routes import posts
    from flaskblog.main.routes import main
    from flaskblog.errors.handlers import errors
    from flaskblog.trading.routes import trading

    app.register_blueprint(users)
    app.register_blueprint(posts)
    app.register_blueprint(main)
    app.register_blueprint(errors)
    app.register_blueprint(trading)

    return app


    section from routes.py within trading folder

    trading = Blueprint('trading', __name__)

    @trading.route("/buy", methods=['GET', 'POST'])
    @login_required
    def buy():
    total_value = calculate_portfolio_value()
    form = BuyForm()
    if form.validate_on_submit():
    price = get_current_price(form.symbol.data.upper())
    transaction = StockTransaction(user_id=current_user.id, stock_symbol=form.symbol.data.upper(), shares=form.shares.data, price= price or 0, transaction_type='buy')
    db.session.add(transaction)
    db.session.commit()
    flash(f'Bought {form.shares.data} shares of {form.symbol.data.upper()}', 'success')
    return redirect(url_for('buy.html'))
    stock_options = ['AAPL', 'MSFT', 'GOOGL', 'AMZN', 'TSLA']
    return render_template('buy.html', form=form, portfolio=current_user.get_portfolio(), advice=get_stock_advice(), total_value=total_value, stock_options=stock_options)


    buy.html within templates folder

    {% extends "layout.html" %}
    {% block content %}
    <h2>Buy Stocks</h2>
    <p><strong>Advice:</strong> {{ advice }}</p>

    <form method="POST">
    {{ form.hidden_tag() }}
    <p>Stock Symbol</p>
    <div class="form-group">
    <select name="symbol" class="form-control">
    {% for ticker in stock_options %}
    <option value="{{ ticker }}">{{ ticker }}</option>
    {% endfor %}
    </select>
    <br>
    {{ form.shares.label }} {{ form.shares(class="form-control") }}
    <br>
    {{ form.submit(class="btn btn-success mt-2") }}
    </div>
    </form>
    <div style="float: right; width: 300px; margin-top: 80px;">
    <h3 class="mt-4">Your Portfolio</h3>
    <ul>
    {% for symbol, shares in portfolio.items() %}
    <li>{{ symbol }} — {{ shares }} shares</li>
    {% else %}
    <li>No holdings yet.</li>
    {% endfor %}
    </ul>
    </div>
    {% endblock %}


    (sorry if its a lot of code, I’ve tried to add the minimum amount to explain the problem)

    Continue reading...

Compartilhe esta Página