Re: sessions in template (outside of views)

2008-06-30 Thread Bobby Roberts

i love you

haha


many thanks to all the Django programmers who have given us such an
awesome platform.


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: sessions in template (outside of views)

2008-06-30 Thread Arien

On Mon, Jun 30, 2008 at 3:27 PM, Bobby Roberts <[EMAIL PROTECTED]> wrote:
>
> in my view I have:
>
>
> from django.template import RequestContext
> from django.template import Template, Context
>
> [... session variables set here...]
>
> return render_to_response('step3.html',
> context_instance=RequestContext(request))
>
>
> and in my template i have:
>
>Account #: 
> {{ request.session.AccountNum }}
>
>
> it prints nothing to the screen unless i explicitly pass a variable.

Are you sure you have activated the request context processor?  In
other words, do you have something like this in your settings file?

TEMPLATE_CONTEXT_PROCESSORS = (
"django.core.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.request",
)

There's more explanation about this in the docs here:
http://www.djangoproject.com/documentation/templates_python/#subclassing-context-requestcontext


Arien

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: sessions in template (outside of views)

2008-06-30 Thread Bobby Roberts

> If you have activated the request context processor, the request is
> *automatically* passed to the template.  (That was the point of all
> this, right?)
>
> So to display the value of request.session['City'], for example, you'd
> use this in your template:
>
>   {{ request.session.City }}
>
> Arien

Yeah I thought it would do that but it really doesn't... here's what i
have...

in my view I have:


from django.template import RequestContext
from django.template import Template, Context

[... session variables set here...]

return render_to_response('step3.html',
context_instance=RequestContext(request))




and in my template i have:

Account #: 
{{ request.session.AccountNum }}


it prints nothing to the screen unless i explicitly pass a variable.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: sessions in template (outside of views)

2008-06-30 Thread Arien

On Mon, Jun 30, 2008 at 8:12 AM, Bobby Roberts <[EMAIL PROTECTED]> wrote:
>
> ok i'm totally lost i guess...
>
> in my view i setup my session variables as such...
>
>request.session['Street2']=request.POST.get('Street2','')
>request.session['City']=request.POST.get('City','')
>request.session['State']=request.POST.get('State','')
>request.session['ZipCode']=request.POST.get('ZipCode','')
>
> and when i want to pass back to the template i am doing the following:
>
>return render_to_response("step2.html", 'form': form},
> context_instance=RequestContext(request))
>
> now my question here is how do i pass those session variables back to
> the template.

If you have activated the request context processor, the request is
*automatically* passed to the template.  (That was the point of all
this, right?)

So to display the value of request.session['City'], for example, you'd
use this in your template:

  {{ request.session.City }}


Arien

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: sessions in template (outside of views)

2008-06-30 Thread Bobby Roberts

ok i'm totally lost i guess...

in my view i setup my session variables as such...


request.session['Street2']=request.POST.get('Street2','')
request.session['City']=request.POST.get('City','')
request.session['State']=request.POST.get('State','')
request.session['ZipCode']=request.POST.get('ZipCode','')


and when i want to pass back to the template i am doing the following:


return render_to_response("step2.html", 'form': form},
context_instance=RequestContext(request))

now my question here is how do i pass those session variables back to
the template.  I've tried building a data dictionary like this:

{'Street2': request.session['Street2'], 'City':
request.session['City'], ...}

but that does nothing.  Please help

BR


On Jun 29, 11:50 am, Arien <[EMAIL PROTECTED]> wrote:
> On Sun, Jun 29, 2008 at 9:08 AM, Bobby Roberts <[EMAIL PROTECTED]> wrote:
>
> > So I have to explicitly pass the session variables to the template to
> > use them?  That kind of defeats the purpose of session variables
> > doesn't it?  If they are in session we should be able to access them
> > easier than passing them from view to template throughout our
> > application.
>
> Variables that happen to hold session data are no different from other
> variables.
>
> If you want to have access to a variable in a template, you'll have to
> make the variable available to the template somehow.  You can do this
> by passing the variable to the template yourself, or (in some cases)
> you can have a context processor do that for you.
>
> This is one of those cases: you can have request.session added
> implicitly if you do what Daniel Roseman wrote and active the
> django.core.context_processors.request context processor, making sure
> to always use a RequestContext when rendering the template.
>
> Arien
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: sessions in template (outside of views)

2008-06-29 Thread Arien

On Sun, Jun 29, 2008 at 9:08 AM, Bobby Roberts <[EMAIL PROTECTED]> wrote:
>
> So I have to explicitly pass the session variables to the template to
> use them?  That kind of defeats the purpose of session variables
> doesn't it?  If they are in session we should be able to access them
> easier than passing them from view to template throughout our
> application.

Variables that happen to hold session data are no different from other
variables.

If you want to have access to a variable in a template, you'll have to
make the variable available to the template somehow.  You can do this
by passing the variable to the template yourself, or (in some cases)
you can have a context processor do that for you.

This is one of those cases: you can have request.session added
implicitly if you do what Daniel Roseman wrote and active the
django.core.context_processors.request context processor, making sure
to always use a RequestContext when rendering the template.


Arien

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: sessions in template (outside of views)

2008-06-29 Thread Bobby Roberts

So I have to explicitly pass the session variables to the template to
use them?  That kind of defeats the purpose of session variables
doesn't it?  If they are in session we should be able to access them
easier than passing them from view to template throughout our
application.


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: sessions in template (outside of views)

2008-06-28 Thread Daniel Roseman

On Jun 27, 9:33 pm, Bobby Roberts <[EMAIL PROTECTED]> wrote:
> i'm trying to view session variables on the screen in a template.  I
> know the session variable has a value because i've tested it in my
> view.  I'm trying this in my template but not getting any results:
>
> Account #: {{ request.session.AccountNum }}
>
> What could I be doing wrong?

You need to enable the request template context processor. Add (or
uncomment) this line to your TEMPLATE_CONTEXT_PROCESSORS tuple in
settings.py:
'django.core.context_processors.request'
You also need to make sure you're using a RequestContext when
rendering the template. If you're using render_to_response, you need
to do something like this:
return render_to_response('my_template.html',
  my_data_dictionary,
 
context_instance=RequestContext(request))

See 
http://www.djangoproject.com/documentation/templates_python/#subclassing-context-requestcontext
for more information.

--
DR.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: sessions in template (outside of views)

2008-06-27 Thread Brandon Taylor

Hi Bobby,

Typically what I do is set the value from the session into a variable
that I pass into the context.

#in views.py
def my_action(request)
account_num = request.session['AccountNum']
return render_to_response('the_template.html', {'account_num' :
account_num})

#in the_template.html
{{ account_num }}

HTH,
Brandon

On Jun 27, 3:33 pm, Bobby Roberts <[EMAIL PROTECTED]> wrote:
> i'm trying to view session variables on the screen in a template.  I
> know the session variable has a value because i've tested it in my
> view.  I'm trying this in my template but not getting any results:
>
> Account #: {{ request.session.AccountNum }}
>
> What could I be doing wrong?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



sessions in template (outside of views)

2008-06-27 Thread Bobby Roberts

i'm trying to view session variables on the screen in a template.  I
know the session variable has a value because i've tested it in my
view.  I'm trying this in my template but not getting any results:

Account #: {{ request.session.AccountNum }}

What could I be doing wrong?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---