惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Docker
爱范儿
爱范儿
T
The Exploit Database - CXSecurity.com
量子位
T
Tailwind CSS Blog
T
Threatpost
The GitHub Blog
The GitHub Blog
AWS News Blog
AWS News Blog
云风的 BLOG
云风的 BLOG
K
Kaspersky official blog
P
Proofpoint News Feed
博客园 - 司徒正美
L
LangChain Blog
T
Threat Research - Cisco Blogs
C
CERT Recently Published Vulnerability Notes
罗磊的独立博客
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 叶小钗
S
Secure Thoughts
The Last Watchdog
The Last Watchdog
Spread Privacy
Spread Privacy
H
Hacker News: Front Page
T
Troy Hunt's Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
W
WeLiveSecurity
A
Arctic Wolf
Apple Machine Learning Research
Apple Machine Learning Research
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
P
Proofpoint News Feed
T
Tor Project blog
T
The Blog of Author Tim Ferriss
I
Intezer
P
Privacy & Cybersecurity Law Blog
美团技术团队
N
Netflix TechBlog - Medium
博客园_首页
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Vulnerabilities – Threatpost
Application and Cybersecurity Blog
Application and Cybersecurity Blog
G
Google Developers Blog
Attack and Defense Labs
Attack and Defense Labs
T
Tenable Blog
月光博客
月光博客
Stack Overflow Blog
Stack Overflow Blog
J
Java Code Geeks
腾讯CDC
Microsoft Security Blog
Microsoft Security Blog
A
About on SuperTechFans
Last Week in AI
Last Week in AI

博客园 - 雨吁的嘘

urllib在某些情况下性能低于urllib2 Unix编程艺术心得 美化fedora字体 ie6 - ie9支持Css特性的补丁 django Mysql初始化命令 Mysql post install 在线转换Postgresql 到Mysql nginx upload-progress配置 从源码安装nginx,并增加upload-porgress模块 让urllib2的DNS亦通过Proxy查询 解决urllib2的DNS远端解析问题,另Django-social-auth很好的支持本地调试 必须为Release版本的Django网站提供404和500.html 更换Chrome为Chromium 为Redhat 6.3安装Famillcollection源 内容丰富的第三方rpm库 多余的拼音导致Python的数据类型错误 CentOS 6.3升级Python2.7.3 解决Tomcat未在IP v4监听问题 Rpm 软件库
django默认启用事务时session异常
雨吁的嘘 · 2012-12-26 · via 博客园 - 雨吁的嘘

django默认的系统配置中,session模块已经启用。其后端采用默认的数据库引擎,也就是session数据会被存储到数据库中。

在有些应用中,为了保障事务的一致性,需要在视图中明确声明或者在全站的配置中启用事物机制。此种情况下,在某些特殊的场景中产生一个冲突,造成session的不同现象。

例如:在异步上传文件时,为了给用户明确的提示。我们希望上传大文件的过程中,显示一个进度条,明确提示用户上传的进度。一般的做法是,将原来的表单提交到一个隐含的iframe中,再用一个定时器任务,从服务器获取上传进度后,更新进度条。

假设处理文件上传的视图叫做upload_view,获取状态的视图叫做progress_view。同时假设upload_view将上传进度保存到session中,progress_view从session中获取数据来反馈客户端进度。

此时,如果upload_view中启用了事务,而且session采用默认的数据库存储。那么,在upload_view完成之前,事务并未提交。session数据不会真正写入后端数据库中。所以progress_view就无法获取地upload_view中更新的状态信息。

解决方案:

  1. 使用非数据库session后端
  2. 进度信息使用其他共享机制。如缓存。