Приложение My Flask уже обслуживает несколько страниц. Я только что сделал channels.html
. Для маршрута я скопировал и изменил /messages
, который уже работает. Затем я попытался добавить ссылку от messages.html
до channels.html
, но получил ошибку: Could not build url for endpoint 'channels'. Did you mean 'index' instead?
Ошибка ссылается на строку <a href="{{ url_for('channels') }}">Channels</a>
в messages.html
. Я проверил орфографию, синтаксис, размещение декоратора и дублирующие имена; все выглядит хорошо. Кроме того, новый код был построен из кода, который был ранее протестирован.
Итак, почему ошибка?
@app.route('/channels', methods=["GET", "POST"])
def channels():
return render_template("channels.html")
@app.route('/messages', methods=["GET", "POST"])
def messages():
return render_template("messages.html")
messages.html (верхняя часть)
{% extends "layout.html" %}
{% block body %}
<div class="container">
<div class="row" style="min-height: 100vh">
<div class="col-md-3 border border-danger rounded">
<div class="row mt-2 justify-content-start">
Header
</div>
<!-- <div class="row mt-2 justify-content-start" id="channelHeader">
Channels
</div>-->
<div class="row mt-2 justify-content-start" id="channels">
<a href="{{ url_for('channels') }}">Channels</a>
</div>
<div class="row justify-content-start" id="dmsg">
Direct Messages
</div>
</div>
<div class="col-md-9 border border-danger rounded">
{% endblock %}
channels.html
{% extends "layout.html" %}
{% block body %}
<div class="container">
<div class="display-3">
<strong>Create A Channel</strong>
</div>
<form action="{{ url_for('channels') }}" id="channelForm" class="mt-4">
<!-- Will need check for duplicate email -->
<div class="form-group">
<label for="channelName">Channel Name</label>
<input type="text" class="form-control" id="channelName" aria-describedby="channelName" placeholder="Enter Channel Name">
</div>
<!-- Will need check for duplicate username -->
<div class="form-group">
<label for="inviteUsers">Invite Other Users (optional)</label>
<input type="text" class="form-control" id="inviteUsers" aria-describedby="inviteUsers" placeholder="Search by name">
</div>
<div class="form-group">
<label for="purpose">Purpose</label>
<textarea type="text" class="form-control" id="purpose" rows="3" placeholder="Purpose">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
{% endblock %}