Hey everyone,

Fairly new to django and trying to write my first site. I have
stumbled across a problem that i can't seem to find much information
on, or perhaps i am looking in the wrong place? Basically i have a
table in the database with phrases, and i run a query on the table to
get a random phrase. I want to put this result into the <title></
title> of the website, however first store it in a session variable
and display that, so the user only sees one phrase each session
instead of seeing a new phrase each page refresh/change.

So i have attempted to pass the request.session to the template tag
via:
{% random_phrase_title request.session %}

Then i have attempted to make the custom template tag:

register = template.Library()

@register.tag
def random_phrase_title(parser, token):
        try:
                tag_name, request.session = token.split_contents()
        except ValueError:
                msg = '%r tag requires a single argument' % token.contents[0]
                raise template.TemplateSyntaxError(msg)
        return ''

class RandomPhrase(template.Node):
        def __init__(self, form, fieldname, nodelist):
                self.form = form
                self.fieldname = fieldname
                self.nodelist = nodelist

        def render(self, context):
                if not request.session['random_phrase_title']:
                        request.session['random_phrase_title'] =
RandomPhrase.objects.order_by('?')
                return request.session['random_phrase_title']

But i can't seem to get the session variables in? Can someone please
help me out with my code above, or show me an example of how n00b i
am :D
Thanks alot!

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to