Hi Russell, Many thanks for your reply. The template tag approach looks good and I will try to use this one.
One further question. If I am using the @register.simple_tag decorator, can I create the view in the views.py file or do I have to create a templatetags directory and follow the full procedure of creating a tag? Sorry if this sounds all basic but I am quite new to this. Thanks a lot in advance. Best wishes, Masud On 21 July 2012 08:52, Russell Keith-Magee <[email protected]> wrote: > On Sat, Jul 21, 2012 at 10:09 AM, Masud Khokhar <[email protected]> > wrote: > > Hi all, > > > > I am using the default 404 view that Django uses. I have created a > custom 404.html page in my templates directory which automatically gets > loaded. Is it possible for this page to load a python dictionary or do I > need to raise http404 myself for that? > > > > In essence, what I am trying to do is load a random message in the > 404.html. There may be a simpler solution for that. > > There sure is: Use a template tag instead. > > > https://docs.djangoproject.com/en/1.4/howto/custom-template-tags/#simple-tags > > If your custom template tag makes the random call, you don't need to > put randomly selected text or a randomly selected value into the > template context. > > The template context for the 404 page isn't something that's > configurable by default, so if you *did* want to go down that path, > you'd have to write your own 404 view, and set that as your 404 > handler. This isn't especially difficult to do, but the template tag > approach will be simpler :-) > > Yours, > Russ Magee %-) > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

