我正在尝试加载我的索引HTML页面,但是我一直在获取“无法为端点'main.index'构建URL”。您是说“索引”吗?”错误。
任何主意
from flask import Flask, render_template
app = Flask(__name__, template_folder="templates")
@app.route('/')
def index():
return render_template("index.html")
if __name__ == '__main__':
app.run(debug=True)
Index.html
{% extends "Base.html" %}
{% block content %}
<div>
<p>
Hello
</p>
</div>
{% endblock %}
Base.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Wooe</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<section>
<header>
<h1>
Parent Watch
</h1>
<nav>
<a href="{{ url_for('main.index') }}" class="navbar-item">Home</a>
<a href="{{ url_for('main.profile') }}" class="navbar-item">Profile</a>
<a href="{{ url_for('auth.login') }}" class="navbar-item">Login</a>
<a href="{{ url_for('auth.signup') }}" class="navbar-item">Sign Up</a>
<a href="{{ url_for('auth.logout') }}" class="navbar-item">Logout</a>
</nav>
</header>
</section>
<div>
{% block content %}
{% endblock %}
</div>
</body>
我添加了索引HTML文件以及索引文件扩展的基本HTML文件
答案 0 :(得分:1)
从问题中显示的代码中猜测,似乎您正在尝试在index.html
<a href="{{ url_for('main.index') }}">Home</a>
并且由于我没有在问题代码中的任何地方注意到blueprints的创建,因此请将其更改为
<a href="{{ url_for('index') }}">Home</a>