Before I decide to use DetailView, I had a url redirect using this solution.
Now that I am using DetailView how do I achieve the same redirect? The name has to be the same since I am using that for LOGIN_REDIRECT_URL in settings.py.
Here is what part of the urls.py looks like
urlpatterns = patterns( 'doors.views',
url(
r'^users/$',
ListView.as_view(
model = User,
template_name = 'doors/users/list.html'
),
),
url(
r'^users/(?P<pk>\d+)/$',
DetailView.as_view(
model = User,
template_name = 'doors/users/detail.html'
),
name = 'users_detail'
),
url( r'^users/self/$', # do some kind of redirect 'users_self_detail', name = 'users_self_detail' ),
)
Let’s not call this redirecting, because that gets confused with HTTP redirects. Let’s just say we want the views to behave the same, ie they should end up in the same code & template. This is where I’d subclass
DetailViewmyself. Something like:Then in
urls.py: