如何修复烧瓶应用程序中未找到错误的页面?

发布于 2025-02-13 18:59:41 字数 1631 浏览 0 评论 0原文

我是新来的烧瓶。我有一个网站,其中有许多页面正常工作。我只是尝试添加一个新的,它正在产生404错误。它似乎像所有其他页面一样设置,所以我不知道原因。这是app.py文件中的相关部分:

@app.route("/verbs")
def verbs():
    return render_template('verbs.html', title="Verbing Out")

@app.route("/tobe")
def toBe():
    return render_template('tobe.html', title="To Be Words")

@app.route("/strategies")
def strategies():
    return render_template('strategies.html', title="Strategies for To Be Words")

称为动词的文件,tobe.html和straltagies.html在同一目录中。后两个工作很好。动词。html返回“找不到。在服务器上找不到请求的URL。如果您手动输入URL,请检查您的拼写并重试。”

所有文件都在模板目录中。这是目录的内容。

-rw-r--r--@ 1 Owner  staff  7188 Jul  5 21:32 examples.html
-rw-r--r--@ 1 Owner  staff    65 Jul  4 10:13 footer.html
-rw-r--r--@ 1 Owner  staff   367 Jul  1 12:55 form.html
-rw-r--r--@ 1 Owner  staff   122 Jul  4 10:13 header.html
-rw-r--r--@ 1 Owner  staff  2833 Jul  7 06:42 home.html
-rw-r--r--@ 1 Owner  staff  1537 Jul  4 09:31 layouts.html
-rw-r--r--@ 1 Owner  staff   764 Jul  5 21:20 passive.html
-rw-r--r--@ 1 Owner  staff  1656 Jul  1 12:55 results.html
-rw-r--r--@ 1 Owner  staff  2657 Jul  7 06:47 strategies.html
-rw-r--r--@ 1 Owner  staff     0 Jul  1 12:55 toBeForm.html
-rw-r--r--@ 1 Owner  staff  2991 Jul  5 21:14 tobe.html
-rw-r--r--@ 1 Owner  staff  2185 Jul  5 21:24 verbs.html

我正在尝试通过此导航菜单访问它们:

 <li><a href="/verbs">Verbing Out</a></li>
 <li><a href="/tobe"> &emsp; To Be Verbs</a></li>
 <li><a href="/strategies"> &emsp; Strategies</a></li>

据我所知,这三个示例是并行设置的,因此我无法弄清楚为什么其中一个行为不同。我想念什么?

I'm new to Flask. I have a site with a number of pages that are working fine. I just tried to add a new one, and it's generating a 404 error. It seems to be set up like all the other pages, so I can't figure out why. Here's the relevant section from the app.py file:

@app.route("/verbs")
def verbs():
    return render_template('verbs.html', title="Verbing Out")

@app.route("/tobe")
def toBe():
    return render_template('tobe.html', title="To Be Words")

@app.route("/strategies")
def strategies():
    return render_template('strategies.html', title="Strategies for To Be Words")

The files called verbs.html, tobe.html, and strategies.html are in the same directory. the latter two work just fine. verbs.html returns "Not Found. The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again."

All of the files are in the templates directory. Here are the contents of the directory.

-rw-r--r--@ 1 Owner  staff  7188 Jul  5 21:32 examples.html
-rw-r--r--@ 1 Owner  staff    65 Jul  4 10:13 footer.html
-rw-r--r--@ 1 Owner  staff   367 Jul  1 12:55 form.html
-rw-r--r--@ 1 Owner  staff   122 Jul  4 10:13 header.html
-rw-r--r--@ 1 Owner  staff  2833 Jul  7 06:42 home.html
-rw-r--r--@ 1 Owner  staff  1537 Jul  4 09:31 layouts.html
-rw-r--r--@ 1 Owner  staff   764 Jul  5 21:20 passive.html
-rw-r--r--@ 1 Owner  staff  1656 Jul  1 12:55 results.html
-rw-r--r--@ 1 Owner  staff  2657 Jul  7 06:47 strategies.html
-rw-r--r--@ 1 Owner  staff     0 Jul  1 12:55 toBeForm.html
-rw-r--r--@ 1 Owner  staff  2991 Jul  5 21:14 tobe.html
-rw-r--r--@ 1 Owner  staff  2185 Jul  5 21:24 verbs.html

I'm trying to access them through this navigation menu:

 <li><a href="/verbs">Verbing Out</a></li>
 <li><a href="/tobe">   To Be Verbs</a></li>
 <li><a href="/strategies">   Strategies</a></li>

As far as I can see, the three examples are set up in parallel, so I can't figure out why one of them acts differently. What am I missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迎风吟唱 2025-02-20 18:59:41

一切都很简单。 Blask默认情况下在模板目录中查找模板,这就是为什么它看不到您的文件。将它们放入模板目录中,它将起作用。

如果我的解释似乎是舌头的,这是

烧瓶将在模板文件夹中查找模板。因此,如果您的应用程序是模块,则该文件夹在该模块旁边,如果是一个软件包,则实际上在您的软件包内部

Everything is simple. Flask looks for templates in the templates directory by default, which is why it doesn't see your files. Put them in the templates directory and it will work.

If my explanation seemed tongue-tied, here is a piece of documentation:

Flask will look for templates in the templates folder. So if your application is a module, this folder is next to that module, if it's a package it's actually inside your package

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文