差分
このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン | ||
python:django:django_programming_memo [2010/12/23 13:46] – ともやん | python:django:django_programming_memo [2015/08/20 10:34] (現在) – 削除 ともやん | ||
---|---|---|---|
行 1: | 行 1: | ||
- | ====== Django プログラミング メモ ====== | ||
- | 以下の内容については Django-1.2.3 を利用して記述している。 | ||
- | ===== プロジェクト設定(settings.py)の修正 ===== | ||
- | - 日本語を使用しても問題が発生しないように、先頭行に以下の記述を追加してファイルを UTF-8 にて保存しなおす。\\ <code python> | ||
- | # -*- coding: utf-8 -*- | ||
- | </ | ||
- | - 3行目にて os モジュールを import し、\\ <code python> | ||
- | import os | ||
- | </ | ||
- | # プロジェクトのルートパスを取得 | ||
- | PROJECT_ROOT = os.path.abspath(os.path.split(__file__)[0]) | ||
- | </ | ||
- | - 6行目に以下のコメントを追加して、デバッグとリリースの切り替えが簡単にできるようにしておく。(先頭 # を5, 6行目で移動するだけ)< | ||
- | #DEBUG = False | ||
- | </ | ||
- | - データベースへの接続設定を行う。(以下は PostgreSQL の例)< | ||
- | DATABASES = { | ||
- | ' | ||
- | # Add ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | } | ||
- | } | ||
- | </ | ||
- | - タイムゾーンをアジア/ | ||
- | TIME_ZONE = ' | ||
- | </ | ||
- | - 言語コードを日本に設定する。< | ||
- | LANGUAGE_CODE = ' | ||
- | </ | ||
- | - プロジェクトサイトのメディアルートを設定する。(以下ではプロジェクトルートの media ディレクトリを設定)\\ '/ | ||
- | MEDIA_ROOT = os.path.join(PROJECT_ROOT, | ||
- | </ | ||
- | - プロジェクトサイトのメディア URL を設定する。(管理サイトのメディア URL と被らないように設定)< | ||
- | MEDIA_URL = '/ | ||
- | </ | ||
- | - 管理サイトのメディア URL を設定する。(プロジェクトサイトのメディア URL と被らないように設定)< | ||
- | ADMIN_MEDIA_PREFIX = '/ | ||
- | </ | ||
- | - セキュリティキーは django-admin.py が生成したものを利用する。(他のプロジェクトのものをコピーして共有しないこと)< | ||
- | SECRET_KEY = ' | ||
- | </ | ||
- | - **django.template.loaders.filesystem.Loader** テンプレートローダが、プロジェクトルートの templates ディレクトリを検索するように設定する。< | ||
- | TEMPLATE_DIRS = ( | ||
- | # Put strings here, like "/ | ||
- | # Always use forward slashes, even on Windows. | ||
- | # Don't forget to use absolute paths, not relative paths. | ||
- | os.path.join(PROJECT_ROOT, | ||
- | ) | ||
- | </ | ||
- | |||
- | ===== 修正後のプロジェクト設定ファイル ===== | ||
- | 上記をすべて反映させたプロジェクト設定ファイルの内容は以下の通り。 | ||
- | <code python 1> | ||
- | # -*- coding: utf-8 -*- | ||
- | # Django settings for pydev_sample project. | ||
- | import os | ||
- | |||
- | DEBUG = True | ||
- | #DEBUG = False | ||
- | TEMPLATE_DEBUG = DEBUG | ||
- | |||
- | ADMINS = ( | ||
- | # ('Your Name', ' | ||
- | ) | ||
- | |||
- | MANAGERS = ADMINS | ||
- | |||
- | # プロジェクトのルートパスを取得 | ||
- | PROJECT_ROOT = os.path.abspath(os.path.split(__file__)[0]) | ||
- | |||
- | DATABASES = { | ||
- | ' | ||
- | # Add ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | } | ||
- | } | ||
- | |||
- | # Local time zone for this installation. Choices can be found here: | ||
- | # http:// | ||
- | # although not all choices may be available on all operating systems. | ||
- | # On Unix systems, a value of None will cause Django to use the same | ||
- | # timezone as the operating system. | ||
- | # If running in a Windows environment this must be set to the same as your | ||
- | # system time zone. | ||
- | TIME_ZONE = ' | ||
- | |||
- | # Language code for this installation. All choices can be found here: | ||
- | # http:// | ||
- | LANGUAGE_CODE = ' | ||
- | |||
- | 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 | ||
- | |||
- | # If you set this to False, Django will not format dates, numbers and | ||
- | # calendars according to the current locale | ||
- | USE_L10N = True | ||
- | |||
- | # Absolute path to the directory that holds media. | ||
- | # Example: "/ | ||
- | MEDIA_ROOT = os.path.join(PROJECT_ROOT, | ||
- | |||
- | # URL that handles the media served from MEDIA_ROOT. Make sure to use a | ||
- | # trailing slash if there is a path component (optional in other cases). | ||
- | # Examples: " | ||
- | MEDIA_URL = '/ | ||
- | |||
- | # URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a | ||
- | # trailing slash. | ||
- | # Examples: " | ||
- | ADMIN_MEDIA_PREFIX = '/ | ||
- | |||
- | # Make this unique, and don't share it with anybody. | ||
- | SECRET_KEY = ' | ||
- | |||
- | # List of callables that know how to import templates from various sources. | ||
- | TEMPLATE_LOADERS = ( | ||
- | ' | ||
- | ' | ||
- | # ' | ||
- | ) | ||
- | |||
- | MIDDLEWARE_CLASSES = ( | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ) | ||
- | |||
- | ROOT_URLCONF = ' | ||
- | |||
- | TEMPLATE_DIRS = ( | ||
- | # Put strings here, like "/ | ||
- | # Always use forward slashes, even on Windows. | ||
- | # Don't forget to use absolute paths, not relative paths. | ||
- | os.path.join(PROJECT_ROOT, | ||
- | ) | ||
- | |||
- | INSTALLED_APPS = ( | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | # Uncomment the next line to enable the admin: | ||
- | # ' | ||
- | # Uncomment the next line to enable admin documentation: | ||
- | # ' | ||
- | ) | ||
- | </ | ||