使用Google App Engine(Webapp) - Python访问Django模板中的会话变量 [英] Accessing session variable in Django template with Google App Engine (Webapp) - Python

查看:118
本文介绍了使用Google App Engine(Webapp) - Python访问Django模板中的会话变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Django模板作为我的前端。在后端,我使用Gaeutilities提供的会话来存储变量(电子邮件)。



前端:

  {%if session.Email%} 
< div id =enterite> WELCOME< em> {{session.Email}}< / EM>< / DIV>
{%else%}
< div id =enterite>< a href =/ login /id =enterite>输入站点< / a> DIV>
{%endif%}

后端:

  self.session = Session()
self.session ['email'] = email
temp = os.path.join(os .path.dirname(__ file __),'templates / index.htm')
outstr = template.render(temp,{})
self.response.out.write(outstr)

问题:如何在服务器端访问存储的会话,并在Django模板(前端)上使用它?



任何人都可以给出这个qns的更新?

解决方案

你需要在django模板上下文中设置会话对象,否?$ / $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ .session})


I have a Django template as my front-end. At the back-end, I used the sessions provided from Gaeutilities to store a variable (email).

Front-end:

{% if session.Email %}
        <div id="entersite">WELCOME <em>{{session.Email}}</em></div>
    {% else %}
        <div id= "entersite"><a href="/login/" id= "entersite">Enter the Site</a></div>
    {% endif %}

Back-end:

self.session = Session()
self.session['email'] = email
            temp = os.path.join(os.path.dirname(__file__),'templates/index.htm')
            outstr = template.render(temp, {})
            self.response.out.write(outstr)

Problem: How do I access the stored session on the server side and use it on the Django template (front-end)?

Anybody can give an update on this qns?

解决方案

You need to set your session object in a django template context, no?

template.render(temp, {'session':self.session})

这篇关于使用Google App Engine(Webapp) - Python访问Django模板中的会话变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆