Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 Jan. 18, 2011 12:22:22

g.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

404 view -> redirect to index


I try to redirect from 404 view to my index page. In url.py i added:
handler404 = 'index.views.custom404'

in my index i have:
def custom404(request):
return HttpResponseRedirect(reverse('index'))

But it doesn't work.
Should I do something more?

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Jan. 18, 2011 12:31:08

Ivo B.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

404 view -> redirect to index


Are you sure, that you have a url pattern called ‘’view? in reverse you have to
pass the name of the rule, not the views method name.

On 18.01.2011, at 13:22, galago wrote:

> I try to redirect from 404 view to my index page. In url.py i added:
> handler404 = 'index.views.custom404'
>
> in my index i have:
> def custom404(request):
> return HttpResponseRedirect(reverse('index'))
>
> But it doesn't work.
> Should I do something more?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
>http://groups.google.com/group/django-users?hl=en.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 Jan. 18, 2011 12:35:40

g.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

404 view -> redirect to index


Yes I have a index pattern:
urlpatterns = patterns('',
url(r'^$', 'index.views.index', name='index'),.......

When I add print to my method:
def custom404(request):
print 'foo'
return HttpResponseRedirect(reverse('index'))

It prints out but it doesn't redirect me to index. Instead it displays my
404.html page.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#4 Jan. 18, 2011 12:42:28

Ivo B.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

404 view -> redirect to index


I guess that django catches the 404 Error Code somehow somewhere else than in
the handler? Maybe you have to set the HTTP Code to 200?


On 18.01.2011, at 13:35, galago wrote:

> Yes I have a index pattern:
> urlpatterns = patterns('',
> url(r'^$', 'index.views.index', name='index'),.......
>
> When I add print to my method:
> def custom404(request):
> print 'foo'
> return HttpResponseRedirect(reverse('index'))
>
> It prints out but it doesn't redirect me to index. Instead it displays my
> 404.html page.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
>http://groups.google.com/group/django-users?hl=en.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#5 Jan. 18, 2011 13:04:07

T.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

404 view -> redirect to index


why just not copy the 'templates/index.html' template to 'templates/404.html' -
ready

*not*sure*about*the*correctness*of*this*


Am 18.01.2011 um 13:42 schrieb Ivo Brodien:

> I guess that django catches the 404 Error Code somehow somewhere else than in
> the handler? Maybe you have to set the HTTP Code to 200?
>
>
> On 18.01.2011, at 13:35, galago wrote:
>
>> Yes I have a index pattern:
>> urlpatterns = patterns('',
>> url(r'^$', 'index.views.index', name='index'),.......
>>
>> When I add print to my method:
>> def custom404(request):
>> print 'foo'
>> return HttpResponseRedirect(reverse('index'))
>>
>> It prints out but it doesn't redirect me to index. Instead it displays my
>> 404.html page.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>>http://groups.google.com/group/django-users?hl=en.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
>http://groups.google.com/group/django-users?hl=en.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#6 Jan. 18, 2011 13:10:33

T.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

404 view -> redirect to index


The book "The definitive Guide to Django" says on page 476:

---8<---

... if you want to override the 404 view, you can specify 'handler404' in your
URLconf, like so:


from django.conf.urls.defaults import *

urlpatterns = patterns ('',
...
)

handler404 = 'mysite.views.my_custom_404_view'



Behind the scenes ...

---8<---


hope this helps,

good luck,
TR



Am 18.01.2011 um 13:42 schrieb Ivo Brodien:

> I guess that django catches the 404 Error Code somehow somewhere else than in
> the handler? Maybe you have to set the HTTP Code to 200?
>
>
> On 18.01.2011, at 13:35, galago wrote:
>
>> Yes I have a index pattern:
>> urlpatterns = patterns('',
>> url(r'^$', 'index.views.index', name='index'),.......
>>
>> When I add print to my method:
>> def custom404(request):
>> print 'foo'
>> return HttpResponseRedirect(reverse('index'))
>>
>> It prints out but it doesn't redirect me to index. Instead it displays my
>> 404.html page.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>>http://groups.google.com/group/django-users?hl=en.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
>http://groups.google.com/group/django-users?hl=en.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#7 Jan. 18, 2011 17:59:53

n.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

404 view -> redirect to index


Thomas: That is what he has.

Make sure you turn DEBUG off. Your custom 404 handler will only be
used when you are not in debug mode.

Cheers

On Jan 18, 5:10 am, Thomas <tho...@googlemail.com> wrote:
> The book "The definitive Guide to Django" says on page 476:
>
> ---8<---
>
> ... if you want to override the 404 view, you can specify 'handler404' in
> your URLconf, like so:
>
> from django.conf.urls.defaults import *
>
> urlpatterns = patterns ('',
> ...
> )
>
> handler404 = 'mysite.views.my_custom_404_view'
>
> Behind the scenes ...
>
> ---8<---
>
> hope this helps,
>
> good luck,
> TR
>
> Am 18.01.2011 um 13:42 schrieb Ivo Brodien:
>
>
>
>
>
>
>
> > I guess that django catches the 404 Error Code somehow somewhere else than
> > in the handler? Maybe you have to set the HTTP Code to 200?
>
> > On 18.01.2011, at 13:35, galago wrote:
>
> >> Yes I have a index pattern:
> >> urlpatterns = patterns('',
> >>     url(r'^$', 'index.views.index', name='index'),.......
>
> >> When I add print to my method:
> >> def custom404(request):
> >>     print 'foo'
> >>     return HttpResponseRedirect(reverse('index'))
>
> >> It prints out but it doesn't redirect me to index. Instead it displays my
> >> 404.html page.
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "Django users" group.
> >> To post to this group, send email to django-users@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> django-users+unsubscr...@googlegroups.com.
> >> For more options, visit this group
> >> athttp://groups.google.com/group/django-users?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-users@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group
> > athttp://groups.google.com/group/django-users?hl=en.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

Board footer

Moderator control

Enjoy the 24th of October
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support