I've already read much about it on stack overflow but now I'm struggling with an issue and don't know how to fix it.
My main.py
looks like the following:
from flask import Flask, jsonify, request
from flask_pymongo import PyMongo
from bson.objectid import ObjectId
from flask_cors import CORS
app = Flask(__name__)
# connect to LiTags database
app.config["MONGO_URI"] = "mongodb://localhost:27017/LiTags"
mongo = PyMongo(app)
CORS(app)
if __name__ == "__main__":
app.run(debug=True)
then I seperated some database requests (MongoDB) in another file(requests.py
). I know that it's not necessary right now because there are not that much requests right now but there will be more after I fixed this problem.
So this is my requests.py
:
from main import app, mongo
from flask import Flask, jsonify, request, Blueprint
from flask_pymongo import PyMongo
from bson.objectid import ObjectId
@app.route("/", methods=["GET"])
def getProjects():
result = []
projects = mongo.db.literature
for field in projects.find():
result.append(
{"_id": str(field["_id"]), "project_name": field["project_name"]})
return jsonify(result)
this is generally my frontend (ReactJS) request to flask:
// get project names from the backend
getProjects() {
axios.get(`http://127.0.0.1:5000/`)
.then(res => {
this.setState({ projects: res.data });
})
}
before I seperated the requests in requests.py
from the main.py
my program worked but now I get an error in the inspect tool in the browser which says:
"GET http://127.0.0.1:5000/ 404 (NOT FOUND)
Error: Request failed with status code 404
at createError (createError.js:17)
at settle (settle.js:19)
at XMLHttpRequest.handleLoad (xhr.js:63)"