[英]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
I'm completely new to Flask. As a beginner I'm trying to print 'Hello World' on a web page.我是 Flask 的新手。作为初学者,我正在尝试在 web 页面上打印“Hello World”。 When run this Flask application, the browser throwing me a 404
error.当运行这个 Flask 应用程序时,浏览器向我抛出404
错误。 It says The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.
它说The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.
The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.
Here is my __init__.py
:这是我的__init__.py
:
from flask import Flask
app = Flask(__name__)
from app import app
My routes.py
file:我的routes.py
文件:
from app import app
@app.route('/')
@app.route('/index')
def index():
return "Hello, World!"
And my microApp.py
file:还有我的microApp.py
文件:
from app import app
Here is my working directory:这是我的工作目录:
My Project/
venv/
app/
__init__.py
routes.py
microApp.py
I set FLASK_APP = microApp.py
and tried to run Flask. But the browser is throwing me an error.我设置FLASK_APP = microApp.py
并尝试运行 Flask。但是浏览器向我抛出一个错误。
Please anyone help me, I'm a noob.请任何人帮助我,我是菜鸟。 Thanks in advance.提前致谢。
When you are importing app
that means your basically importing __init__.py
file.当您导入app
时,这意味着您基本上导入了__init__.py
文件。 The __init__.py
files are modules that initialize the packages. __init__.py
文件是初始化包的模块。 modules So in your __init__.py
file you importing again 'app'. modules所以在你的__init__.py
文件中你再次导入'app'。 Here you have to call 'routes'.在这里,您必须调用“路线”。
A server that does print "Hello world":打印“Hello world”的服务器:
from flask import Flask
app = Flask(__name__)
@app.route("/")
@app.route('/index')
def hello_world():
return "Hello world!"
app.run('127.0.0.1', port=5500)
I got here trying to solve an error on a more complex page, involving chartjs.我来到这里试图解决涉及chartjs的更复杂页面上的错误。
What solved to me was sending back to an older library:对我来说解决的是发回一个旧图书馆:
Instead of: https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.min.js' Solved with: https://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/Chart.min.js'而不是: https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.min.js'解决了: https://cdnjs.cloudflare.com/ajax/libs/Chart。 js/1.0.2/Chart.min.js'
Newer library did not support the type of graph that I wanted.较新的库不支持我想要的图形类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.