简体   繁体   English

Flask: Not Found 在服务器上找不到请求的 URL。 如果您手动输入 URL,请检查您的拼写并重试

[英]Flask: Not Found The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again

Error "Not Found The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again."错误“未找到请求的 URL 在服务器上未找到。如果您手动输入 URL,请检查拼写并重试。” occurs when pressing menu-item 'Redactiehulp'.当按下菜单项“Redactiehulp”时发生。 How can I solve this?我该如何解决这个问题?

When pressing "Add", "Login" or "Register", the correct screens are properly shown.按“添加”、“登录”或“注册”时,会正确显示正确的屏幕。

My app.py is:我的 app.py 是:

from ast import Str
from enum import unique
from turtle import st
from typing_extensions import Self
from flask import Flask, render_template, request, redirect, url_for, flash
from datetime import datetime
from logging import DEBUG
from forms import RegistrationForm, LoginForm
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)

app.logger.setLevel(DEBUG)

feedback=[]

def store_feedback(url):
    feedback.append(dict(
        url=url,
        user='Looneycorn',
        date=datetime.utcnow()
    ))

@app.route('/')
@app.route('/index')
def index():
    return render_template('index.html')

@app.route('/add', methods=['GET','POST'])
def add():
    if request.method == "POST":
        url = request.form['url']
        store_feedback(url)
        app.logger.debug('stored feedback:' + url)
        flash("Your feedback : " + url)
        return redirect(url_for('index'))
    return render_template('add.html')

@app.route("/register", methods = ['GET', 'POST'])
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        flash('Account created')
        return redirect(url_for('login'))
    if form.errors:
        flash('Validation Errors: ' + str(form.errors))
        app.logger.error('Validation error(s):\n' + str(form.errors))
    return render_template('register.html', title='Register', form = form)

@app.route('/resulttekst/<nieuwetekst>')
def resulttekst(nieuwetekst):
    return 'Resultaat: %s' % nieuwetekst

@app.route('/redactiehulp', methods = ['GET', 'POST'])
def redactiehulp():
    app.logger.debug('Redactiehulp, ingevoerde tekst:' + invoertekst)
    if request.method == "POST":
        invoertekst = request.form['invoertekst']
        newtekst = '111-' + invoertekst + '-222'
        return redirect(url_for('resulttekst', nieuwetekst = newtekst))
    else:
        invoertekst = request.args.get('invoertekst')
        newtekst = '333-' + invoertekst + '-444'
        return redirect(url_for('resulttekst', nieuwetekst = newtekst))
    return render_template('redactiehulp.html')

@app.route('/login', methods = ['GET', 'POST'])
def login():
    form = LoginForm()
    if form.validate_on_submit():
            flash('Logged in!')
            return redirect(url_for('index'))
        else:
            flash('Login unsuccessful')
    return render_template('login.html', title='Login', form = form)

if __name__ == "__main__":
    app.run(debug=True)

PS.附言。 redactiehulp.html is: redactiehulp.html 是:

{% extends "base.html" %}

{% block title %}
Redactiehulp
{% endblock %}

{% block content %}

    <section>
        <form action="" method = "post">
            <h2>Redactiehulp</h2>
            <p>Voer de te redigeren text in en druk vervolgens op 'Redigeer' voor het resultaat:</p>
            <p>
                <input type="text" name="invoertekst">
            </p>
            <p>
                <button type="submit">Redigeer</button>
            </p>
        </form>
    </section>

{% endblock %}

{% block sidebar %}
{% endblock %}

When pressing "Add", "Login" or "Register", the correct screens are properly shown.按“添加”、“登录”或“注册”时,会正确显示正确的屏幕。 However, when "Redactiehulp" is clicked the following error is shown: "Not Found The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again."但是,当单击“Redactiehulp”时,会显示以下错误:“在服务器上未找到请求的 URL。如果您手动输入 URL,请检查拼写并重试。”

add.html, login.html and register.html but also redactiehulp.html, are all in the same \templates folder. add.html、login.html 和 register.html 还有 redactiehulp.html,都在同一个 \templates 文件夹中。

You code looks like good, just make sure template name should be match same you mentioned.您的代码看起来不错,只需确保模板名称应与您提到的相同。 Otherwise Try to use two scenario for change route.否则尝试使用两种方案来更改路线。

<a href="{{ url_for('redactiehulp') }}">Go To Redactiehulp</a>

And

<a href="/redactiehulp">Go To Redactiehulp</a>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 FLASK - 在服务器上找不到请求的 URL。 如果您手动输入 URL 请检查您的拼写并重试 - FLASK - The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again Flask - 404 未找到:在服务器上未找到请求的 URL。 如果您手动输入 URL,请检查您的拼写并重试 - Flask - 404 Not found : The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again Flask: Not Found 在服务器上找不到请求的 URL。 如果您手动输入了 URL,请检查您的拼写并重试 - Flask: Not Found The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again python flask URL 错误:&#39;在服务器上找不到请求的 URL。 如果您手动输入了 URL,请检查您的拼写并重试。 - python flask URL error: 'The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.' 在服务器上找不到请求的 URL。 如果您手动输入 URL,请检查您的拼写并重试 - The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again Flask 错误:在服务器上找不到请求的 URL。 如果您手动输入 URL 请检查您的拼写并重试 - Flask error: The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again Python Flask API:在服务器上找不到请求的 ZE6B391A8D2C4D45902A23A8B6587。 如果您手动输入 URL 请检查您的拼写并重试 - Python Flask API : The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again Flask 应用程序 - 错误 404,在服务器上找不到请求的 URL。 如果您手动输入了 URL,请检查您的拼写并重试 - Flask app - Error 404, The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again 为什么我会收到“在服务器上找不到请求的 URL。如果您手动输入了 URL,请检查您的拼写并重试” - Why am I getting "The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again" 在服务器上找不到请求的 URL。 如果您手动输入了 URL,请检查您的拼写并重试。 404 - The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again. 404
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM