﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
28999	Document how to use class-based views if you want to reverse by them by instance	Andrew Standley	Clifford Gama	"This is primarily an issue with CBV {{{get_view()}}} method.
However this affects basically all url reverse resolution as urls.base {{{reverse()}}} -> urls.resolvers {{{get_resolver()}}} -> urls.resolvers **RegexURLResolver** -> utils.datastructures **MultiValueDict** -> dict() {{{__getitem__()}}} which uses the key's hash value. 

I discovered this while attempting to reverse a class based view. No matter what I tried I could not get a reverse url. Quite a bit of testing and digging later, the issue appears to be that {{{as_view()}} creates a new view function on every call, and every one of these functions has a unique hash. This means that using the result of one call to ""as_view"" as the key in **MultiValueDict** results in a value you can not retrieve with a subsequent call.

{{{
from testapp.views import MyCBView
from django.utils.datastructures import MultiValueDict, MultiValueDictKeyError

lookups = MultiValueDict()
first_call = MyCBView.as_view()
second_call = MyCBView.as_view()

# Does Not Work
lookups[first_call] = ""Test Retrieval""
try:
    test = lookups[second_call]
except MultiValueDictKeyError:
    print(""Lookup Failed {} != {}"".format(first_call.__hash__(), second_call.__hash__()))

# Works
test = lookups[first_call]
print(""Lookup Succeeded test={}"".format(test))
}}}

I am fairly certain that it is not intended (and certainly not documented) that you must store the return of ""as_view"", and use that stored value in your urlconf, if you ever want to be able to reverse using a CBV instance."	Cleanup/optimization	closed	Documentation	2.0	Normal	fixed	url reverse cbv		Ready for checkin	1	0	0	0	0	0
