Opened 7 years ago
Closed 7 years ago
#29365 closed Bug (invalid)
the reverse function does not work in the current application, which was included in the URL using namespace
Reported by: | blins | Owned by: | nobody |
---|---|---|---|
Component: | Core (URLs) | Version: | 2.0 |
Severity: | Normal | Keywords: | reverse url current_app |
Cc: | blins@… | Triage Stage: | Unreviewed |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
in app/urls.py
urlpatterns = [ url(r'^$', Index.as_view(), name = 'index'), url(r'^all/$', All.as_view(), name = 'all'), ]
in project urls.py
... path('app/', include('app.urls', namespace='app')), ...
and in index template app/index.html
{%url all %}
function produces an error "NoReverseMatch at /app/. Reverse for 'all' not found. 'all' is not a valid view function or pattern name."
Attachments (2)
Change History (6)
by , 7 years ago
Attachment: | base.py.patch added |
---|
comment:1 by , 7 years ago
When I setup ULRconfs as you describe, I see "ImproperlyConfigured: Specifying a namespace in include() without providing an app_name is not supported. Set the app_name attribute in the included module, or pass a 2-tuple containing the list of patterns and app_name instead." Maybe the steps to reproduce aren't complete... can you provide a sample project?
comment:2 by , 7 years ago
Resolution: | → needsinfo |
---|---|
Status: | new → closed |
comment:3 by , 7 years ago
Resolution: | needsinfo |
---|---|
Status: | closed → new |
I add project.zip in attachements
comment:4 by , 7 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
See the docs on Reversing namespaced URLs.
Basically you need to include the namespace when using reverse (or the url template tag).
You'll want this:
{%url 'app:all' %}
Also: You've included the app_name
in your app/urls.py
so your call to include
already provides an application_namespace
. It's not necessary here to use the namespace
parameter as well. (This adds an instance_namespace
, which you very likely don't need.)
It's worth reviewing the whole URL Namespaces section slowly, and the `include()` docs to make sure you're clear on the behaviour here.
patch