'werkzeug.routing.BuildError: Could not build url for endpoint robotReports' with values ['id']. Did you mean 'reports' instead?
im working on a website with flask so im trying to generate an url to see the reports linked to robots , so i have this route :
@app.route("/robotReports/<int:id>")
def reportRobots(id):
headings = (
"#",
"Report Name",
"Date",
"Robot",
"View Logs",
)
reports = Report.query.filter_by(robot_id=id).all()
print(report)
return render_template("reportsforRobot.html" , reports=reports, headings=headings)
and im trying to call it on my HTML page as
<a href="{{ url_for('robotReports', id=robot.id)}}">
but when i run it gets
werkzeug.routing.BuildError: Could not build url for endpoint 'robotReports' with values ['id']. Did you mean 'reports' instead?
so , it works when i change it to
<a href="{{ url_for('reports', id=robot.id)}}">
because reports its an already working route but the url that i get is
/reports?id=X , and i want reports/X
this is the code for reports
@app.route("/reports")
def reports():
headings = (
"#",
"Report Name",
"Date",
"Robot",
"View Logs",
)
return render_template("reports.html", headings=headings)
im really new on this so maybe its a stupid thing, any help is apreciated
Solution 1:[1]
So i changed to this
@app.route("/robotReports/<int:id>")
def robotReports(id):
headings = (
"#",
"Report Name",
"Date",
"Robot",
"View Logs",
)
reports = Report.query.filter_by(robot_id=id).all()
print(report)
return render_template("reportsforRobot.html" , reports=reports, headings=headings)
and
<a href="{{url_for('robotReports', id=robot.id)}}">
and now it works. idk what i did
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Joaquin Bracci |
