Some Django tips, 以及如何在GAE环境下部署reusable app/lib


Some Django tips, 以及如何在GAE环境下部署reusable app/lib

Published on Sat 04 Apr 2009 10:04 ( 1 year, 5 months ago)
Django Google 学习

首先学习了几篇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:

  1. Django applications, which are listed in the INSTALLED_APPLICATIONS list 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 of from app_name import ... for any app_name in your application list.
  2. If your application contains any models, they must be in a models namespace in the application directory. This means either models.py or a directory called models/, containing all you models. We'll talk about this a bit more below.
  3. Any template tags you write must live under a directory called templatetags in your application directory. You can have subdirectories underneath the templatetags/ 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

Living 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:


Search related in web:

Custom Search

RSS Feed

One click subscribe this blog in your google reader!

Be social!


Want to say something here? please sign in



Blog posts link to this page
What are friends tweeting?
Tags cloud
Monthly Archives