Opened 15 months ago
Closed 15 months ago
#34812 closed New feature (worksforme)
Validate that URLConf modules contain a urlpatterns entry
Reported by: | The Epic | Owned by: | nobody |
---|---|---|---|
Component: | Core (URLs) | Version: | 4.2 |
Severity: | Normal | 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
Hey everyone. I've seen a few people on Discord mention that Django reported circular imports due to their URL configs, and in at least one case the problem was that the user made a typo in urlpatterns
.
I think it would be grand if Django checked for the existence of the urlpatterns
attribute when passing a module to include
and raised a clearer Exception if it is absent.
Change History (3)
follow-up: 2 comment:1 by , 15 months ago
comment:2 by , 15 months ago
Replying to David Sanders:
Hello,
Django already does this with:
django.core.exceptions.ImproperlyConfigured: The included URLconf '<module 'foo.urls' from '/path/to/foo/urls.py'>' does not appear to have any patterns in it. If you see the 'urlpatterns' variable with valid patterns in the file then the issue is probably caused by a circular import.
🤔
Oh, you're right. I guess the message should be clearer. I don't really see how circular imports would affect it.
comment:3 by , 15 months ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
Ok marking as worksforme… raise a discussion on the Django Forum if you'd like to discuss changing the message 👍
Hello,
Django already does this with:
🤔