インストール
http://djangoproject.jp/doc/ja/1.0/intro/install.html
sudo python setup.py installするだけ。
チュートリアル
http://djangoproject.jp/doc/ja/1.0/intro/tutorial01.html
ん?django-admin.pyがないといわれる。
$ sudo ln -s /Library/Frameworks/Python.framework/Versions/2.6/bin/django-admin.py /usr/bin
しといた。
プロジェクト作成
django-admin.py startproject hogehoge
サーバ起動
python manage.py runserver
デフォルトのポートは8000。
Djangoではプロジェクトとアプリケーションの2種類を区別する。
プロジェクト=アプリケーション+設定 という感じ。
python manage.py startapp foobar
ここでRailsとの違いを。
Djangoではコントローラのことをビューという。
Djangoではビューのことをテンプレートという。
settings.pyのDatabaseの設定でつまづいた。
https://docs.djangoproject.com/en/dev/ref/settings/
(1)Sqlite3を使う場合は、Databaseに
(2)touchで空ファイルを作っておく。下の例だと、test.db
(3)(2)で作ったデータベースファイルまでの絶対パスをNAME欄に記入する。
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. 'NAME': '/Users/(ユーザ名)/programming/django/ecsite/db/test.db', \ # Or path to database file if using sqlite3. 'USER': '', # Not used with sqlite3. 'PASSWORD': '', # Not used with sqlite3. 'HOST': '', # Set to empty string for localhost. No\ t used with sqlite3. 'PORT': '8000', # Set to empty string for default. \ Not used with sqlite3. } }
またもやはまった。
INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', 'polls', #←ここ!manage.pyと同階層から相対パスで指定。階層はドット表記(.)。 # Uncomment the next line to enable the admin: # 'django.contrib.admin', # Uncomment the next line to enable admin documentation: # 'django.contrib.admindocs', )
疲れた。以下のをみてやり直そう。
http://www.ueblog.org/blog/entry/django_kihon/