EAD: Bandit Johnson
johnsonqu · 2007-04-30
<< Offline时代?
|
首 页
|
个人英雄与团队合作 >>
2007-04-30
[Django]management.py与其他
- [
Python
]
版权声明
:转载时请以超链接形式标明文章原始出处和作者信息及
本声明
http://johnsonqu.blogbus.com/logs/5210532.html
今天有空,可以好好再看看上次下载的那个snapboard的例子,其中有一些代码是对于Django的扩展应用的范例。
我最开始感兴趣的是syncdb之后,它会询问是否创建一些测试的users/threads/posts。看起来应该是预先留好的接口。仔细看了看,snapboard的根目录下有个management.py文件,里面有处理的代码。其中,使用了dispatcher和signals,我不是很明白,就查了一下,发现Django的wiki那里有个详细的说明
文档
。对于不同Signal的含义都做了说明,经常用到的就是那个post_syncdb了。
在B-List的一篇关于如何规划Django应用的文章中,有关于management.py的说明。
To provide custom Python functions which will run when the application is installed, put them in a file named
management.py
, and use Django’s internal dispatcher to connect your functions to the
post_syncdb
signal.
另外,James也谈到了其他conventions.
At the application level, I usually drop in a few more files depending on exactly what the application is going to be using:
If the application defines any custom manipulators, I put them in a file called
forms.py
instead of in the views file.
If there are multiple custom managers in the app, I put them in a file called
managers.py
instead of the models file.
If I’m defining any custom context processors, I put them in a file called
context_processors.py
.
If I’m setting up any custom dispatcher signals, they go in a file called
signals.py
.
If the application is setting up any syndication feeds, the feed classes go in a file called
feeds.py
. Similarly, sitemap classes go in
sitemaps.py
.
Middleware classes go in a file called
middleware.py
.
Any miscellaneous code which doesn’t clearly go anywhere else goes in a file or module called
utils
.
随机文章:
[Django] PIM进展
2007-09-07
[Django]备忘两则
2007-07-30
[Django]PIM的Worklog改进 (jQuery动态刷新下拉框)
2007-05-25
[Django]Model的一些问题
2007-05-24
[Django]newforms与TinyMCE
2007-05-12
收藏到:
Del.icio.us
Tag:
Python
Django
引用地址:
发表于
14:05:58
|
编辑
|
继续话题
|
转发
|
推荐
发表评论
原始快照:web.archive.org