In this lesson, you’ll review what you just saw and practice some more debugging by looking at error messages in Django and get some tips on how to debug a NoReverseMatch
error. If you get a NoReverseMatch
error, there are a few files you’ll want to check:
-
urls.py
: Make sure you have an app name defined as well as a name for your path so you can build valid namespaces. -
your_template.html
: If you’re using URL linking, make sure that the string that you’re using is a valid Django namespace with the name of the app as well as the path. Also make sure that you have an argument that you’re passing correctly, with a space right after the namespace.
Note: The code snippet in the slide around 1:45 should read {'project': project}
. You want to pass the Project object under the singular key so that you’re able to access it via project
in your template.
reblark on Nov. 13, 2019
Things above are things that I did a “million” times. When I finally found the problem, it was a typo in PyCharm, my typo. I could not see it because of the layout of the frame in PyCharm. Trust me, I went over my code character by character. I finally found it by looking at the error messages many times and they simply told me that I wasn’t passing the right address, but from my perspective I was passing a hard code number or project.pk…Looking more deeply into the error message, I found a display of my code. When I saw it, I thought “that isn’t my code, that’s crazy.” Of course, it was my code. So, I went back to PyCharm and scrolled up and down, left and right. I found it. I couldn’t believe it. It was a result of not paying attention to auto completion and winding up with two extra }}s. That’s all it was and it took me 2 hours of work and two or three messages to you. I would like to make a suggestion. This video is good but only as far as it goes. I did everything this video suggest several times and did not find the error. That’s simply because there is more to debugging than this. As I have mentioned previously, I really like your pressing the point that error messages are your friends. However, one needs to read the messages thoroughly. Just knowing that it’s a “NoReverseMatch” error is incomplete. I would emphasize always, always, looking for typo errors in your code. I just happen to be a very smart guy and an excellent typists. Throughout this course I have been stunned and amazed at the number of either careless, sloppy or stupid mistakes I have made, not in the coding, but in the typing. Dan even sent me a note about one. I have learned a lot from this course about how bad my coding is, not from a theory and rules standpoint. As I improve my typing/coding I will get better and better. I think there may be others who have this particular problem and it might be good to emphasize that as part of your excellent focus on “errors are your friends” message. Cheers, Martin. and, thanks again.