![](/img/trans.png)
[英]werkzeug.routing.BuildError: Could not build url for endpoint 'profile'. Did you mean 'index' instead?
[英]werkzeug.routing.BuildError: Could not build url for endpoint 'auth.Esp_Index'. Did you mean 'auth.login' instead?
我正在嘗試構建一個簡單的注冊和登錄表單,但我遇到了錯誤。 我試圖通過閱讀文檔來修復它,但沒有運氣。 你能幫忙嗎?
“werkzeug.routing.BuildError:無法為端點 'auth.Esp_Index' 構建 url。你的意思是 'auth.login' 嗎?”
init .py中的代碼
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager
db = SQLAlchemy()
def create_app():
app = Flask(__name__)
app.config['SECRET_KEY'] = '\xbd\xc5H\xe5\xd0rX\xcc\x11\x99'
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://support:support@rea-lnx-tdin01:5432/postgres'
db.init_app(app)
from .auth import auth as auth_blueprint
app.register_blueprint(auth_blueprint)
return app
auth.py中的代碼
from flask import Blueprint, render_template, redirect
auth = Blueprint('auth',__name__)
@auth.route('/login', methods=["GET", "POST"])
def login():
return render_template('Loginpage.html')
@auth.route('/Esp_Index', methods=["GET", "POST"])
def registration():
#return '<h1> welcome to Index page </h1>'
return render_template('Esp_Index.html')
Html 模板
基本模板中的代碼
<!DOCTYPE html>
<html lang="en">
<head>
{% block head %}
<title>{% block title %}{% endblock %}</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </script >
<!-- Custom Theme files -->
<link href="{{url_for('static',filename='css/Styles.css')}}" rel="stylesheet" type="text/css" media="all" />
<!-- //Custom Theme files -->
<link href="//fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i" rel="stylesheet"> <!-- //web font -->
{% endblock %}
</head>
<body>
<div id="content" >
<a href="{{url_for('auth.Esp_Index')}}" />
<a href="{{url_for('auth.login')}}" />
{% block content %}
{% endblock %}
</div>
<ul class="colorlib-bubbles">
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
Esp_Index.html 中的代碼
{% extends "ESP_Base.html" %}
{% block title %}Web Console{% endblock %}
{% block head %}
{{ super() }}
{% endblock %}
{% block body %}
{% block content %}
<h1>Web Console SignUp Portal Form</h1>
{% with errors = get_flashed_messages() %}
{% if errors %}
{% for error in errors %}
<div class="alert alert-warning alert-dismissible fade show" role="alert">
<strong>{{ error }}</strong>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
{% endfor %}
{% endif %}
{% endwith %}
<div class="main-w3layouts wrapper">
<div class="main-agileinfo">
<div class="agileits-top">
<form action="" method="POST">
<input type="text" name="Username" placeholder="Username" value="{{request.form.get.Username}}">
<input type="Email" name="Email" placeholder="Email" value="{{request.form.get.Email}}">
<input type="Password" name="Password" placeholder="Password" value="{{request.form.get.Password}}">
<input type="Password" name="RepeatPassword" placeholder="ConfirmPassword" value="{{request.form.get.RepeatPassword}}">
<input type="submit" value="SIGNUP">
</form>
<p>Don't have an Account? <a href="{{ url_for('login') }} "> Login Now!</a></p>
</div>
</div>
</div>
{% endblock %}
{% endblock %}
Loginpage.html中的代碼
{% extends "ESP_Base.html" %}
{% block title %}Web Console {% endblock %}
{% block head %}
{{ super() }}
{% endblock %}
{% block body %}
{% block content %}
<h1>Web Console SignUp Portal Form</h1>
{% with errors = get_flashed_messages() %}
{% if errors %}
{% for error in errors %}
<div class="alert alert-warning alert-dismissible fade show" role="alert">
<strong>{{ error }}</strong>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
{% endfor %}
{% endif %}
{% endwith %}
<div class="main-agileinfo">
<div class="agileits-top">
<form action="" method="POST">
<input type="text" name="Username" placeholder="Username" value="{{request.form.get.Username}}">
<input type="Password" name="Password" placeholder="Password" value="{{request.form.get.Password}}">
<p><input type = "submit" value = "Login"/></p>
</form>
</div>
</div>
{% endblock %}
{% endblock %}
When build a URL with url_for()
in Flask, you should pass the endpoint of the view function, the default value of endpoint is the name of the view function , not the URL rule.
所以你應該在你的模板中寫下這個:
<a href="{{ url_for('auth.registration') }}" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.