RedirectView()

58 views
Skip to first unread message

Brad Rice

unread,
Feb 23, 2015, 9:30:55 AM2/23/15
to django...@googlegroups.com
I'm using RedirectView and it is redirecting to my app, but is not rendering the view in the app I am pointing to.

I want to redirect my root / to my app /web

I have this in my primary app urls:

url(r'^$', RedirectView.as_view(url='/web/', permanent=False)),

I have this in web.urls.py

url(r'^$', IndexView.as_view(), name='index'),

I have his in my web.vews.py

class Index(View):

def get(self, request, *args, **kwargs):
return HttpResponse('Hello, World!')

when I go to / I do get redirected to /web/ but I get a index.html template display rather than Hello World. It isn't finding my Index(View) class for some reason.

Can anybody explain to me how this should work?

--
Brad Rice
brad...@gmail.com
--
To succeed in life, you need two things: ignorance and confidence.
-Mark Twain

Andreas Kuhne

unread,
Feb 23, 2015, 10:01:53 AM2/23/15
to django...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMqTKp4vQmDez7tJSZ54j96huCfhTiCY3F2-g_Lpgq-8sgPMEw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Hi Brad,

You have not correctly written the web.urls.py file. It should be:

url(r'^web/$', IndexView.as_view(), name='index'),

The urls file doesn't know about in which app it resides, så you have to add the complete url yourself. As long as you don't add the web.urls.py into your main urls.py file with:

url(r'^web/', include(web.urls)),

then your code should work ok.

Regards,

Andréas

Brad Rice

unread,
Feb 23, 2015, 10:53:45 AM2/23/15
to django...@googlegroups.com
OK, thanks. I had added that. I was just putting the url to the particular file in place. This is my whole urls.py at the top: So you are saying don't add the line that includes the web.urls?

urlpatterns = patterns('',

    url(r'^admin/', include(admin.site.urls)),
    url(r'^$', RedirectView.as_view(url='/web/', permanent=False)),
    url(r'^web/', include('web.urls', namespace='web'),
        )
)

Then this is the web urls.py

urlpatterns = patterns('',
url(r'^$', IndexView.as_view(), name='index'),
url(r'^gallery', gallery, name='gallery'),
)
Reply all
Reply to author
Forward
0 new messages