Blog信息 |
blog名称: 日志总数:1304 评论数量:2242 留言数量:5 访问次数:7627659 建立时间:2006年5月29日 |

| |
[Django]Django 学习笔记 - Apache2 + FastCGI 软件技术
lhwork 发表于 2007/2/3 11:27:11 |
昨天开始学习Django站点的生产服务器(Production Server),尝试了一下lighttpd和Apache2,最后决定采用Apache2来搭建整个环境(其实lighttpd更为方便一些)。
虽然Apache2 + mod_python就可以跑Django站点服务,但是听说FastCGI有更优异的性能。
FastCGI applications are fast because they're persistent. There is no
per-request startup and initialization overhead. This makes possible
the development of applications which would otherwise be impractical
within the CGI paradigm (e.g. a huge Perl script, or an application
which requires a connection to |
|
[Django]Running Django with FCGI and lighttpd 软件技术
lhwork 发表于 2007/2/2 15:46:24 |
Update: I maintain the actually descriptions now in my trac system. See the FCGI+lighty description for Django. There are different ways to run Django on your machine. One way is only for development: use the django-admin.py runserver command as documented in the tutorial. The builtin server isn't good for production use, though |
|
[Django]Django, lighttpd and FCGI, second take 软件技术
lhwork 发表于 2007/2/2 15:45:09 |
In my first take at this stuff I gave a sample on how to run django projects behind lighttpd with simple FCGI scripts integrated with the server. I will elaborate a bit on this stuff, with a way to combine lighttpd and Django that gives much more flexibility in distributing Django applications over machines. This is especially important if you expect high loads on your servers. Of cou |
|
[Django]Django的Cookie和Session 软件技术
lhwork 发表于 2007/2/2 15:37:07 |
在两个月前,就有同仁在论坛里面提到,Django的Cookie和Session有什么区别,由于我当时也只是懂得如何用这两个东东,但是有什么区别,确不知道,所以当时我说等我有时间好好看看,然后再做回答。由于一直很忙,没有想到一下子等到今天,实在是很抱歉。今晚忽然想起看了看代码,终于看了一个明白。
在Django里面,使用Cookie和Session看起来好像是一样的,使用的方式都是request.COOKIES[XXX]和request.session[XXX],其中XXX是您想要取得的东西的key,但是这两者的原理和实现方式确是非常的不同。 首先介绍Cookie,只要是HTTP协议,就会有COOKIE这个东西; 只要您的浏览器没有禁用Cookie,就 可是使用它。而且是不分用什么语言,用什么框架,因为这是在HTTP协议的层面支持的,浏览器会把您设置的XXX的这个Cookie在Response之后保存到您的本地机器,在下次您向服务器提交或者浏览的时候会把上次保存下来的COOKIE带上发送向服务器;说到这里我们应该澄清一个概念,就是BS结构理论 |
|
[Django]django0.95修改了Auth模块 软件技术
lhwork 发表于 2007/2/2 15:24:47 |
就是在session里面加入了一个新的key:BACKEND_SESSION_KEY request.session[BACKEND_SESSION_KEY] = user.backend以前的版本,登录时,简单修改session就可以 request.session[SESSION_KEY] = user.id但是0.95版本强制必须先调用django.contrib.auth.authenticate,这样也节省了很多工作,login对应的函数就一行代码
from< |
|
[Django]django模板中的filter只能支持一个附加参数 软件技术
lhwork 发表于 2007/2/2 15:22:50 |
想自定义一个复杂一点的filter,折腾了很久,刷新网页看效果,始终不能成功。于是打开django的代码查看,发现根本就不能支持多个参数 .解析模板文件是在${django}\template\__init__.py文件里面,这里定义了一个正则字符串filter_raw_string ,这个字符串展开如下
^_(" |
|
[Django]使用函数调用来默认值填充models中字段的默认值 软件技术
lhwork 发表于 2007/2/1 21:15:32 |
使用函数调用来默认值填充models中字段的默认值,比如使用 datetime.datetime.now来填充 字段类型为日期型的时候最为有用,当然不只可以用于日期型字段。扩展一下,完 全可以使 用自定义的方法来填充默认值
Model source code
from django.db import models from datetime import datetime
class Article(models.Model): headline = models.CharField(maxlength=100,
default=’Default headline’) pub_date =
models.DateTimeField(default=datetime.now)
def __str__(self): return self.headline
|
|
[Django]Django中这样翻页,一个字,简单 软件技术
lhwork 发表于 2007/2/1 21:13:13 |
29. Object pagination
Django provides a framework for paginating a list of objects in a few
lines of code. This is often useful for dividing search results or long
lists of objects into easily readable pages.
Model source code
from django.db import models
class Article(models.Model): headline = models.CharField(maxlength=100,
default=’Default headline’) pub_date = models.DateTimeField()
def __str__(self): return self.headline
Sample API |
|
|