Some Django tips, 以及如何在GAE环境下部署reusable app/lib
首先学习了几篇Django小技巧的文章:
1. Django Tips: Source Code Filenames
Django中仅有的几个文件/目录名convention:
almost nothing has to be called by a particular name or put in a particular place. The number of required files are few enough we can list all of them:
- Django applications, which are listed in the
INSTALLED_APPLICATIONSlist in your settings file, must be an importable Python module. Mostly for things like the automatic interface and constructing reverse relations between models (if model A refers to model B, then model B can also refer back to model A without any extra annotation). So Django must be able to do the equivalent offrom app_name import ...for anyapp_namein your application list.- If your application contains any models, they must be in a
modelsnamespace in the application directory. This means eithermodels.pyor a directory calledmodels/, containing all you models. We'll talk about this a bit more below.- Any template tags you write must live under a directory called
templatetagsin your application directory. You can have subdirectories underneath thetemplatetags/directory, but that must be the root of the hierarchy.Everything else is unrestricted (constrained only by Python's syntax and semantics).
View仅仅是需要特定参数和特定返回值的callable:
VIews
A Django view is just a Python callable that accepts at least one argument (the HttpRequest object as the first positional argument) and returns an HttpResponse. Any function that meets that interface is sufficient. You can store it anywhere. You can load it however you like. It doesn't even have to be a function (a class with a
__call__method is used in some cases in the Django source, for example).
2. Django Tip: Developing Without Projects
这两篇文章的观点我非常支持,尤其要考虑resuable app, 就应该这么做,否则自己还得在自己的projects之间维护版本。
James Bennett的目录和路径如下设置:
~/dev/personal/, on my laptop which holds the full setup of every application, including its parent directory for packaging purposes; for example, django-registration lives in~/dev/personal/django-registration/. This directory, and the package directories inside it, are not on my Python path.
~/dev/python-local/— is on my Python path, and it holds all of the third-party Python software…Each of the package directories in
~/dev/personal/contains a Python module which holds the actual application code, and I’ve just got symlinks from~/dev/python-local/into those directories, which means that the application modules are right on my Python path, with the packaging information conveniently out of the way
如何在GAE环境下部署reusable app/lib
Windows环境下没有*nix那么方便地建立链接,要做到这点,需要下载sysinternal的junction.
为了能在GAE环境下工作,我是把第三方的lib, app放在各自的目录下, 我自己的reusable的app单独放在各自的目录下,而在GAE project的目录下用junction来建立到所需的lib, app的连接。这样即不需要在各个项目内复制第三方的lib和可重用的app, 在deploy到的时候也可以一次性发布到GAE.
Related posts:
- Google Wave game over了...
- 我的Nexus One坏了~ :(
- 升级我的Nexus One到Android 2.2 FroYo
- 自以为是
- 什么是好的Developer experience?
- Google/Aardvark 作恶新举证?试图把social media推广方式注册为专利!
- Adsense使用了Google Search history
- Nexus One的轨迹球存在的意义
- app-engine-patch is now officially dead
- GMail 自动显示了flickr的照片!
Search related in web: