[英]404 error Flask with correct link
I'm working on flask
app, but whenever I try to run run.py
, I get a 404
.我正在开发flask
应用程序,但是每当我尝试运行run.py
,我都会收到404
。 Here is my views page:这是我的意见页面:
from flask import render_template, flash,
redirect, Flask, request
from app import app
import sqlite3 as sql
import csv
import os
app = Flask(__name__)
app.url_map.strict_slashes = False
@app.route('/')
def home():
print(10999)
return render_template('base.html')
@app.route('/2018_draft')
def list():
con = sql.connect("database.db")
con.row_factory = sql.Row
cur = con.cursor()
cur.execute("SELECT * FROM BPM")
rows = cur.fetchall();
return render_template("table.html",rows = rows)
if __name__ == '__main__':
app.run(debug = True)
Ignoring the sqlite code, why am I getting a 404
?忽略 sqlite 代码,为什么我会收到404
? It doesn't work when I manually go to localhost:5000/base.html
, or localhost:5000/
or localhost:5000/2018_draft
either.当我手动转到localhost:5000/base.html
或localhost:5000/
或localhost:5000/2018_draft
它localhost:5000/2018_draft
。
I believe that the issue is on the path of templates, probably Flask can't find them.我相信问题出在模板的路径上,可能 Flask 找不到它们。
Assuming that your file's name is run.py the organization of folders should be:假设您的文件名为 run.py,文件夹的组织应该是:
/parent_folder
/static
/templates
run.py
/static is the folder that you put js/css files that your html may import. /static 是您放置 html 可能导入的 js/css 文件的文件夹。 /templates you put the html files that you want to render with render_template("table.html",rows = rows) /templates 你把你想用 render_template("table.html",rows = rows) 渲染的 html 文件
I'm not sure why you import the from app import app
, it is not necessary unless you create the Flask(__name__)
in other file.我不确定为什么要导入from app import app
,除非您在其他文件中创建Flask(__name__)
,否则没有必要。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.