talkpython / 100daysofweb-with-python-course

Demo code and resources for our 100 Days of Web in Python Course
https://training.talkpython.fm/courses/explore_100days_web/100-days-of-web-in-python
630 stars 391 forks source link

Fix order of API view functions #29

Closed tbrlpld closed 4 years ago

tbrlpld commented 4 years ago

Before, the routes/views with parameters in the URL where defined first. E.g. @api.route("/api/movie/genre/{genre}") was defined before @api.route("/api/movie/genre/all").

When trying to hit the URL for /api/movie/genre/all the response would be empty. This is because the this would not trigger the desired view, but the parameterized view would be passes genre = all. Since there are no movies with the genre "all" the response would be empty.

To solve this issue, the ordering of the routes/views had to be adjusted. Now the most specific views are defined first, and then the more flexible views are defined.

mikeckennedy commented 4 years ago

Thanks. Something must have changed because this was OK when I recorded it AFAIK. Appreciate the update.

tbrlpld commented 4 years ago

Yea, I assume there was a responder update that changed how the routes are looked up. I did not confirm this, but I saw it working in the videos too 😄

On Jan 28, 2020, at 09:14, Michael Kennedy notifications@github.com wrote:

 Thanks. Something must have changed because this was OK when I recorded it AFAIK. Appreciate the update.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.