# session.py
from django.http import HttpResponse
def writeSession(request):
request.session['name'] = 'Bill'
request.session['age'] = 20
return HttpResponse('writeSession')
def readSession(request):
result = ''
name = request.session.get('name')
age = request.session.get('age')
if name:
result = '<h2>name:<font color="red">' + name + '</font></h2>'
if age:
result = '<h2>age:<font color="blue">' + age + '</font></h2>'
return HttpResponse(result, content_type='text/html')
# urls.py
from django.conf.urls import url
from . import session
urlpatterns = [
url(r'^writeSession$', session.writeSession),
url(r'^readSession$', session.readSession)
]
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。