因此,我一直在遵循这个教程,如何建立一个基本的 flask 网站关闭youtube Tutorial。目前试图添加HTML模板,这是给我“500内部服务器错误”与应用程序错误的CMD。
我的python代码
from flask import Flask, redirect, url_for, render_template
app = Flask(__name__)
@app.route("/<name>")
def home(name):
return render_template("index.html", content=name)
if __name__ == "__main__":
app.run()
**my html code **
<!DOCTYPE html>
<html>
<head>
<title>ETF World!</title>
</head>
<body>
<h1>Explore the world of Exchange Traded Funds</h1>
<p>{{content}}</p>
</body>
</html>
错误
Traceback (most recent call last):
File "C:\Users\Bradley J Stewart\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\flask\app.py", line 2077, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\Bradley J Stewart\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\flask\app.py", line 1525, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\Bradley J Stewart\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\flask\app.py", line 1523, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\Bradley J Stewart\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\flask\app.py", line 1509, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
TypeError: home() missing 1 required positional argument: 'name'
我希望当我在URL中输入一个正斜杠时,网站可以正常工作,动态信息可以从后端传递到我所写的“内容”变量的前端。不能100%确定视频是否相关,因为它已经有3年了
任何帮助都是非常感谢的。
1条答案
按热度按时间whitzsjs1#
不过,我的手机正好能用。main.py
index.html:
还要确保将index.html放到模板文件夹中,因为flask会查看该文件夹。