[Fixed]-NoReverseMatch in url in django app

1👍

Trying to put all your Genres in the URL as options is a very bad idea. Apart from anything else, the query will only be evaluated once, so the URL will only accept Genres that had already been created at server startup.

Instead, this is the kind of thing you check in the view, with something like get_object_or_404; it has exactly the same result, of returning a 404 if the genre doesn’t exist.

However, in this particular case the error is because the value of genre.code that you are passing to the {% url %} tag is empty for some reason. Without seeing the rest of the template or the view, though, we can’t tell you why.

Leave a comment