自宅合宿

チュートリアルも見つつこちらも試行錯誤。
現在、chroot な籠の中の /usr/lib/python2.4/site-packages は以下

$ ls /usr/lib/python2.4/site-packages/
Feedjack-0.9.12-py2.4.egg  
README                     
debconf.py  
django      
easy-install.pth  
feedparser.py     
feedparser.pyc  
mod_python      
setuptools-0.6c8-py2.4.egg
setuptools.pth
$

大体 syncdb とかどうするんだろ、と言いつつ django-admin.py でナニできるらしい、との情報げと。試しに python な REPL で

>>> import feedjack;
>>>

だったのですが、これは python なモジュールの探索パスには入ってる、と見て良いのだろうか。てーか google 先生方面をうろついてると setting.py だとか INSTALLED_APPS だのといった語がやたらに出てくるんですが、ネトから落として setup.py install しただけの環境だからかどうか、そのようなソレが全然無い。
# しかしエントリ二個同時に書いてるとゆーのもイカガなものか。

え??

もしかしてアプリを自分で作って云々なの??
その中の settings.py の INSTALLED_APPS の中に入れて import とかして使いなさい、とかそゆ意味??
とりあえず作ってみよう、ってその前にブラウザなウィンドウ大杉でさすがに端末重い。ちょっと整理してから云々。ついでにここでエントリ投入しとく。

作る

ええと

$ django-admin.py startproject rssreader
$ cd rssreader
$ ls
__init__.py  manage.py  settings.py  urls.py
$

で、とりあえず settings.py の中身を拝見。

$ cat settings.py
# Django settings for rssreader project.

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = (
    # ('Your Name', 'your_email@domain.com'),
)

MANAGERS = ADMINS

DATABASE_ENGINE = ''           # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'ado_mssql'.
DATABASE_NAME = ''             # Or path to database file if using sqlite3.
DATABASE_USER = ''             # Not used with sqlite3.
DATABASE_PASSWORD = ''         # Not used with sqlite3.
DATABASE_HOST = ''             # Set to empty string for localhost. Not used with sqlite3.
DATABASE_PORT = ''             # Set to empty string for default. Not used with sqlite3.

# Local time zone for this installation. Choices can be found here:
# http://www.postgresql.org/docs/8.1/static/datetime-keywords.html#DATETIME-TIMEZONE-SET-TABLE
# although not all variations may be possible on all operating systems.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'America/Chicago'

# Language code for this installation. All choices can be found here:
# http://www.w3.org/TR/REC-html40/struct/dirlang.html#langcodes
# http://blogs.law.harvard.edu/tech/stories/storyReader$15
LANGUAGE_CODE = 'en-us'

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
MEDIA_URL = ''

# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
# trailing slash.
# Examples: "http://foo.com/media/", "/media/".
ADMIN_MEDIA_PREFIX = '/media/'

# Make this unique, and don't share it with anybody.
SECRET_KEY = '0ai#=dtq^pgpoysgr+9*n)dy!d1e*c7&ug4h^vc77sb!rbebmv'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.load_template_source',
    'django.template.loaders.app_directories.load_template_source',
#     'django.template.loaders.eggs.load_template_source',
)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.middleware.doc.XViewMiddleware',
)

ROOT_URLCONF = 'rssreader.urls'

TEMPLATE_DIRS = (
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
)

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
)
$

ち。長いな。これはDjango の設定な文書にエントリな解説があると見た。SD 増刊なカンペによれば

  • DATABASE_云々
  • TIME_ZONE
  • LANGUAGE_CODE
  • INSTALLED_APPS

あたりを修正すれば良い模様。修正分のみ以下

DATABASE_ENGINE = 'sqlite3'
DATABASE_NAME = '/home/guest/rssreader/rss.db'
TIME_ZONE = 'Japan'
LANGUAGE_CODE = 'ja'
INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'feedjack',
)

これで syncdb せい、とあるな。どうなるか。

$ python manage.py syncdb
(中略
django.core.exceptions.ImproperlyConfigured: Error loading pysqlite2 module: No module named pysqlite2
$

む。なんだこれは。

$ dpkg --get-selections|grep sqlite
libsqlite3-0                                    install
$ apt-cache search pysqlite2
python-pysqlite1.1 - python interface to SQLite 3
python-pysqlite2 - python interface to SQLite 3
python-sqlite - python interface to SQLite 2
$

python-pysqlite2 入れてリトライ。

$ python manage.py syncdb
Error: Couldn't install apps, because there were errors in one or more models:
feedjack: cannot import name ugettext_lazy
$

あら。面倒なので略しますが feedjack.models に

from django.utils.translation import ugettext_lazy as _

なソレがあって解決できない模様、なの??
よく見ると django なモジュールに見えますな。でも、/usr/lib/python2.4/site-packages/django 配下に utils/translation ってディレクトリがある。でも ugettext_lazy ってのが見当らん。
配下の trans_real.py には DjangoTranslation というクラス定義があって、gettext_module.GNUTranslations というクラスを継承している風に読める。
で、でびあんパケジを検索してみたんですが、Etch には django も twisted もあるんだねぇ、と言いつつ python- なパケジ大杉。試しに python-django が依存しているパケジを見るために -s で apt-get install してみたら

Inst python-support (0.5.6 Debian:4.0r3/stable)
Inst python-django (0.95.1-1 Debian:4.0r3/stable)
Conf python-support (0.5.6 Debian:4.0r3/stable)
Conf python-django (0.95.1-1 Debian:4.0r3/stable)

との事。試しに python-support 入れてみる??

とほほ

当たり前かもしれませんが微妙。もしかして TIME_ZONE が微妙?? ってコトで 'Asia/Tokyo' でヤッてみましたが NG。import できんって言ってるんだからそりゃ違うわな。
うーん。

Django??

svn からオトしてみました。

$ django-admin.py --version
0.97-pre-SVN-7520
$

で、ナニ

$ python manage.py syncdb
Creating table auth_message
Creating table auth_group
Creating table auth_user
Creating table auth_permission
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table feedjack_feed
Creating table feedjack_site
Creating table feedjack_subscriber
Creating table feedjack_tag
Creating table feedjack_link
Creating table feedjack_post

You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): 

を。通った。一応 superuser なソレも作っておくってコトで以下続き

Would you like to create one now? (yes/no): yes
Username (Leave blank to use 'guest'): admin
E-mail address: yamanetoshi@gmail.com
Password: 
Password (again): 
Superuser created successfully.
Installing index for auth.Message model
Installing index for auth.Permission model
Installing index for feedjack.Subscriber model
Installing index for feedjack.Post model
$

これで一応 admin なソレは動いてるはず、なのかな??
あ、カンペによると urls.py の以下をナニ

     (r'^admin/', include('django.contrib.admin.urls')),

どうもイケマセン、と言いつつ admin にアクセスしたらオチた。settings.py の INSTALLED_APPS に以下を追加

    'django.contrib.admin',

で、ログイン画面が出ました。やれやれ。んで、ログインしたらまたオチた。syncdb してないのか。

$ python manage.py syncdb
Creating table django_admin_log
Installing index for admin.LogEntry model
$

いやはや。出ました。なんかヨタりまくっています。