April 18, 2010
Django: apache でのスタティックファイルのデプロイをmod_rewriteでやる

例えば、
http://mysite.com/pr/account/profile/
で、Djangoのアカウントプロファルの処理をしてレンダリング結果を返すときに、
イメージ(*.jpg,*.gif,*.png…)とか、その他のスタティックファイル(*.css,
*.js…)は
相対パスでテンプレートに書きたいです。 URIがスラッシュで終わったらfastcgiに処理を振り分けて、拡張子付きできたら
スタティックファイルパスに
mod_rewriteすればいけそうです。

もしも、

でテンプレートに指定してあれば、http:
//mysite.com/pr/account/profile/img/header.gif がリクエストされるので、
これをhttp://mysite.com/prstatic/account/profile/img/header.gif に振り分
けるということですね。 /home/hdknr/.ve/djtweet/src/djcube/www/static/account/profile/img/header.gif
ファイルがパブリッシュされます。

# WSGI fastcgi プロセス
WSGIDaemonProcess ve_campaign user=www-data group=www-data
threads=25 
python-path=/home/hdknr/.ve/djtweet/lib/python2.5/site-packages:/home/hdknr/.ve/djtweet/bin # WSGI 仮想ディレクトリ (prアプリケーション)
WSGIScriptAlias /pr
/home/hdknr/.ve/djtweet/src/djcube/www/apache/website.wsgi

# Django Admin UI メディアファイル
Alias /pr/media
/home/hdknr/.ve/djtweet/lib/python2.5/site-packages/django/contrib/admin/media # prアプリケーションスタティクファイルのパス
Alias /prstatic /home/hdknr/.ve/djtweet/src/djcube/www/static

# WSGI アプリケーションパラメータ
WSGIReloadMechanism Process
WSGIProcessGroup ve_campaign
WSGIApplicationGroup %{SERVER}

Options All   # 拡張子付きのURLであればスタティックファイルにリライト。
RewriteEngine On
RewriteRule ^.+[txt|css|jpg|gif]$ /prstatic%{REQUEST_URI}

Posted via email from 原宿工業大学 | Comment »

April 9, 2010
uWSGI

uWSGI is a fast (pure C), self-healing, developer-friendly WSGI server, aimed for professional python webapps deployment and development. Over time it has evolved in a complete stack for networked/clustered python applications, implementing message/object passing and process management. It uses the uwsgi (all lowercase) protocol for all the networking/interprocess communications. From the 0.9.5 release it includes a plugin loading technology that can be used to add support for other languages or platform. A Lua wsapi adaptor, a PSGI handler and an Erlang message exchanger are already available.

Posted via web from hdknr’s posterous | Comment »

March 10, 2010
PasteDeploy Application Factory for Django — twod.wsgi v1.0a2 documentation

Deployment

The following is a sample WSGI script for mod_wsgi:

from paste.deploy import loadapp    application = loadapp("config:/path/to/your/config.ini")  

Posted via web from 原宿工業大学 | Comment »

February 24, 2010
Python:logging

ログ関係のモジュールを用意する。


(djtweet)hdknr@deblen:~/.ve/djtweet/src/djcube/www/website$ more journal.py
import logging
#
def initialize():
    # apache error.log
    logging.basicConfig(level=logging.DEBUG,
                     format=’%(asctime)s %(levelname)s %(message)s’)

WSGIスクリプトとか最初に動くコードで初期化する

from app.journal import initialize
initialize()

プログラムの中で記録する

import logging
logging.debug(‘@@@’+str(type(ret))+str(ret.toPostArgs()))
mod_wsgiの場合、error.log にログされます。

Posted via email from 原宿工業大学 | Comment »

December 21, 2009
HgWebDirStepByStep - Mercurial

8.1.3. Configuring Apache with mod_wsgi

Using mod_wsgi is recommended over using mod_python. It’s one of the faster and more efficient ways of serving hgweb(dir).

You can use the hgwebdir.wsgi script (it lives where other Mercurial scripts live, and works with Mercurial 1.0 and later), which references a hgwebdir.conf file in the CONFIG variable:

from mercurial.hgweb.hgweb_mod import hgweb  from mercurial.hgweb.hgwebdir_mod import hgwebdir    CONFIG = '/var/hg/public.config'  application = hgwebdir(CONFIG)

This is really an ordinary Python module, but it uses a wsgi extension to make it clear what its use is.

You then need to add this to your httpd.conf (or the vhost config):

WSGIScriptAlias / /var/hg/script/public.wsgi  <Directory /var/hg/script>  Order deny,allow  Allow from all  </Directory>

Since you’re allowing some permissions to the directory the .wsgi script is in, you probably don’t want to put the script in a directory that also contains your repositories.

NOTE: the default hgwebdir.wsgi uses ‘hgweb.config’ as configuration path. This may not be what you expect. If you find yourself with a working but empty installation, try to set this to the full path where your hgweb.config is situated

Posted via web from hdknr’s posterous | Comment »