【发布时间】:2021-07-30 08:08:19
【问题描述】:
我的所有.html 文件都存在于模板文件夹中。
我在一个名为 tour1.html 的特定文件上收到 404 错误
我将它的路由定义为:
@app.route('/tour1.html')
def tour1():
return render_template('tour1.html')
完全错误是
"GET tour1.html HTTP/1.1" 404
此外,当我在 VS Code Live Server 上运行时,链接工作正常,因此 html 文件中没有问题。
这是项目树的样子
myproject\
Data\
fonts\
GraphQL\
js\
Model\
MongoDB\
static\
css\
img\
templates\
404.html
about.html
contact.html
aruserinterface.html
index.html
tour1.html
main.py
这是 main.py 中的代码
from MongoDB.script import Mongodb
from MongoDB.mongo import query
from flask_pymongo import PyMongo
from flask import Flask, jsonify, request, redirect, render_template, url_for, send_from_directory
from geopy.geocoders import Nominatim
import json, bson
import folium
mongoDb = Mongodb()
app = Flask(__name__)
app.config['MONGODB_SETTINGS'] = {'db':'Cluster0', 'alias':'default'}
@app.route('/')
def home():
return render_template('index.html')
@app.route('/about.html')
def about():
return render_template('about.html')
@app.route('/contact.html')
def contact():
return render_template('contact.html')
@app.route('/aruserinterface.html')
def aruserinterface():
return render_template('aruserinterface.html')
@app.route('/tour1')
def tour1():
return render_template('tour1.html')
@app.errorhandler(404)
def not_found(e):
return render_template("404.html")
if __name__ == '__main__':
app.run('127.0.0.1', port=5100)
【问题讨论】:
-
如果问题是关于
flask,为什么要django标签? -
我怀疑
tour1.html文件是否在templates文件夹中?请重新检查! -
@Xitiz 是!刚刚也重新检查了
-
@Ram 因为我看到有人为 django 提出同样的问题,我认为任何有 django 知识的人也可以提供帮助 :)
-
同时发布您的完整代码和文件夹结构。