Opened 16 years ago
Closed 16 years ago
#10599 closed (fixed)
URLNode raises "Reverse for 'settings.view_name' ... not found."
Reported by: | nishio | Owned by: | nobody |
---|---|---|---|
Component: | Template system | Version: | 1.0 |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
URLNode raises strange exception as below
Reverse for 'settings.new_game' with arguments '(u'1',)' and keyword arguments '{}' not found.
It is because URLNode try to find "project_name.view_name" even if there is no project name. This error message makes users confused. It should fail fast.
I attached a patch.
Index: django/template/defaulttags.py =================================================================== --- django/template/defaulttags.py (revision 10138) +++ django/template/defaulttags.py (working copy) @@ -371,6 +371,7 @@ try: url = reverse(self.view_name, args=args, kwargs=kwargs) except NoReverseMatch: + if "." not in settings.SETTINGS_MODULE: raise project_name = settings.SETTINGS_MODULE.split('.')[0] try: url = reverse(project_name + '.' + self.view_name,
Attachments (1)
Change History (5)
by , 16 years ago
Attachment: | patch.diff added |
---|
comment:1 by , 16 years ago
This is a known problem (I'm be surprised if this wasn't a dupe of some other ticket, but I can't find it at the moment), however the proposed fix isn't correct. The presence or otherwise of a period in the settings module's import path isn't indicative of anything about the project directory. We should basically not report anything from that last block if it raises an exception, since it's really just a safety net for beginners.
We do need a better error reporting there, but this isn't the way to do it.
comment:2 by , 16 years ago
I agree that the proposal is not correct solution, but I think it is better than now. The following code is also incorrect. It assumes SETTINGS_MODULE is "project_name.settings" style. That's why the error message strange.
project_name = settings.SETTINGS_MODULE.split('.')[0]
This fix is not the better error reporting but a better one.
comment:3 by , 16 years ago
Sorry, I made 2 mistake in above comment.
I agree that the proposal is not perfect solution, but I think it is better than now. The following code is also incorrect. It assumes SETTINGS_MODULE is "project_name.settings" style. That's why the error message strange.
project_name = settings.SETTINGS_MODULE.split('.')[0]
This fix is not the best error reporting but a better one.
comment:4 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
patch