#28999: URL Reverse does not work for CBV (Class Based Views)
---------------------------------+--------------------------------------
Reporter: airstandley | Owner: nobody
Type: Bug | Status: new
Component: Generic views | Version: 2.0
Severity: Normal | Resolution:
Keywords: url reverse cbv | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Comment (by Marten Kenbeek):
Replying to [comment:3 airstandley]:
> So I think I have a possible fix, but I'm not yet set up for
contributing to Django so I haven't run the test suite on it. Preliminary
testing appeared to work.
>
> I would be interested in hearing others thoughts before investing more
time into this.
>
> <snip>
The `callable_view` would compare equal regardless of its `initkwargs`, I
don't think that's the behaviour we'd want. We can compare the initkwargs
as well, but that becomes kinda iffy when more complex arguments don't
necessarily compare equal, in which case we get the same problem but in a
less obvious way that's harder to debug.
I'd much rather document the pattern of calling `.as_view()` once in
`views.py` and using the result as if it were a function-based view (if
that's not yet documented), e.g.:
{{{
class MyDetailView(DetailView):
...
my_detail_view = MyDetailView.as_view()
}}}
Then you can use `my_detail_view` as if it were a function-based view, and
reversing would work as expected. I think that should solve your usecase
as well without requiring changes to the way `.as_view()` and `reverse()`
work.
--
Ticket URL: <https://code.djangoproject.com/ticket/28999#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/069.2c5d8a357b537650719bffbe97ed0682%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.