Reputation: 1
All of my .html
files are present in templates folder.
I'm getting a 404 error on one particular file called tour1.html
I have defined its route as:
@app.route('/tour1.html')
def tour1():
return render_template('tour1.html')
Full Error is
"GET tour1.html HTTP/1.1" 404
Additionally, the linking works fine when I run on VS Code Live Server, so no issue in html
files.
Here is what the project tree looks like
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
this is code in 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)
Upvotes: 0
Views: 2202
Reputation: 3987
I think you are doing tour1.html
in url but your route is just tour1
.
If you're doing this :
@app.route('/tour1')
def tour1():
return render_template('tour1.html')
Then you have to do /tour1
in url rather then tour1.html
.
If you want to do /tour1.html
in url then you should do this:
@app.route('/tour1.html')
def tour1():
return render_template('tour1.html')
Upvotes: 1
Reputation: 1627
I dont think the .html needs to be part of the route, check if this works:
@app.route('/tour1') # removed the .html from the URL route definition
def tour1():
return render_template('tour1.html')
if you're still getting a 404 error you should test the route using a curl command like this:
curl -X GET "http://127.0.0.1:5100/tour1"
or a more specialized tool like Postman
Upvotes: 0