2009年7月アーカイブ

djangoをインストール後、新しいウェブアプリケーション・ディレクトリを作成する。
$ django-admin.py startproject <ウェブアプリケーション名>

作成したウェブアプリをテスト起動するには
$ python manage.py runserver localhost:8000


ウェブアプリケーションの
を適用させるにはDBにテーブルを作る必要がある。それをするには下記のコマンドで実行

$ python manage.py syncdb
Creating table auth_permission
Creating table auth_group
Creating table auth_user
Creating table auth_message
Creating table django_content_type
Creating table django_session
Creating table django_site

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): yes
Username (Leave blank to use 'tkobayashi'):
E-mail address: koba206@gmail.com
Password:
Password (again):
Superuser created successfully.
Installing index for auth.Permission model
Installing index for auth.Message model

参考URL:
http://docs.djangoproject.com/en/dev/intro/tutorial01/#intro-tutorial01

DjangoでMySQLを使う際にはまずMySQLdbをインストールする必要がある。

#python
>>> import MySQLdb
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
ImportError: No module named MySQLdb
とMySQLdbが入っていないエラーが出る。
pythonではapt-getみたいな自動インストールツールがある。それがeasy_install。これを使うには、まずsetuptoolsをインストールする必要がある。

wget http://pypi.python.org/packages/2.5/s/setuptools/setuptools-0.6c9-py2.5.egg#md5=fe67c3e5a17b12c0e7c541b7ea43a8e6
sh setuptools-0.6c9-py2.5.egg

wget http://sourceforge.net/projects/mysql-python/files/mysql-python-test/MySQL_python-1.2.3c1-py2.6-linux-i686.egg
easy_install MySQL_python-1.2.3c1-py2.6-linux-i686.egg


↓結局こっちのほうがうまくいった
apt-get install python-mysqldb
apt-get install libmysqlclient15-dev

root@koba206:/usr/local/src# python
Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb

↑エラーが出なかったので、これでOK

参考URL
http://sourceforge.net/projects/mysql-python/files/