[英]Getting error 404 while trying to run flask app in python
attached is the picture of how my directories are up i am trying to run my app with flask, and I am referencing the proper directories, yet I keep getting an error 404 message.附件是我的目录如何启动的图片,我正在尝试使用 Flask 运行我的应用程序,并且我正在引用正确的目录,但我一直收到错误 404 消息。 I do not know what I am doing wrong.
我不知道我做错了什么。
Here is my the code to run the app in the app.py section:这是我在 app.py 部分运行应用程序的代码:
@app.route('/')
def math():
#return(y)
return render_template('index2.html', variable = y)
if __name__ == "__main__":
app.run(debug = True)
and here is my html code这是我的 html 代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>Scrolling Nav - Start Bootstrap Template</title>
<!-- Bootstrap core CSS -->
<link href="/static2/static2/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="/static2/static2/css/scrolling-nav.css" rel="stylesheet">
<!-- Bootstrap core JavaScript -->
<script src="/static2/static2/vendor/jquery/jquery.min.js"></script>
<script src="/static2/static2/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- Plugin JavaScript -->
<script src="/static2/static2/vendor/jquery-easing/jquery.easing.min.js"></script>
<!-- Custom JavaScript for this theme -->
<script src="/static2/static2/js/scrolling-nav.js"></script>
</body>
</html>
the scrolling -nav.js is in the correct folder for sure.滚动 -nav.js 肯定在正确的文件夹中。
Please let me know if there is more information needed for this question.如果这个问题需要更多信息,请告诉我。
For references to static files in Flask it's considered best practice to use the url_for
function eg对于 Flask 中静态文件的引用,使用
url_for
函数被认为是最佳实践,例如
<script src="{{url_for('static', filename='js/scrolling-nav.js')}}"></script>
Other than that, if that is your full HTML then it's just a javascript file, do you have the basic HTML stuff in there as well?除此之外,如果那是您的完整 HTML,那么它只是一个 javascript 文件,您是否也有基本的 HTML 内容? eg
例如
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
Content
</body>
<html>
Is index2.html
stored in a templates folder? index2.html
是否存储在模板文件夹中?
I got it.我知道了。 My directories name was static2.
我的目录名称是 static2。 The directories name must be "static" for the css and js files to be pulled.
对于要拉取的 css 和 js 文件,目录名称必须为“静态”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.