python:django:django_programming_memo

差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

両方とも前のリビジョン 前のリビジョン
次のリビジョン
前のリビジョン
python:django:django_programming_memo [2015/08/15 21:10] ともやん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 -*- 
-</code> 
-  - BASE_DIR が提供されるように変わりました。<code python> 
-# Build paths inside the project like this: os.path.join(BASE_DIR, ...) 
-import os 
- 
-BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 
-</code><del>3行目にて os モジュールを import し、</del><code python> 
-import os 
-</code><del>15行目付近で PROJECT_ROOT の取得を追加する。(各動作環境のパスの差異を吸収する)\\ %%__file__%% == '/private/django_proj/settings.py' の場合、'/private/django_proj/' を取得。\\ %%__file__%% == 'D:\My Projects\django_proj\settings.py' の場合、'D:\My Projects\django_proj' を取得。</del><code python> 
-# プロジェクトのルートパスを取得 
-PROJECT_ROOT = os.path.abspath(os.path.split(__file__)[0]) 
-</code> 
-  - 6行目に以下のコメントを追加して、デバッグとリリースの切り替えが簡単にできるようにしておく。(先頭 # を5, 6行目で移動するだけ)<code python> 
-#DEBUG = False 
-</code> 
-  - データベースへの接続設定を行う。(以下は PostgreSQL の例)<code python> 
-DATABASES = { 
-    'default': { 
-        # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. 
-        'ENGINE'    : 'django.db.backends.postgresql_psycopg2', 
-        'NAME'      : 'pydev_sample',   # Or path to database file if using sqlite3. 
-        'USER'      : 'pydev_sample',   # Not used with sqlite3. 
-        'PASSWORD'  : 'test123',        # Not used with sqlite3. 
-        'HOST'      : '',               # Set to empty string for localhost. Not used with sqlite3. 
-        'PORT'      : '',               # Set to empty string for default. Not used with sqlite3. 
-    } 
-} 
-</code> 
-  - タイムゾーンをアジア/東京に設定する。<code python> 
-TIME_ZONE = 'Asia/Tokyo' 
-</code> 
-  - 言語コードを日本に設定する。<code python> 
-LANGUAGE_CODE = 'ja' 
-</code> 
-  - プロジェクトサイトのメディアルートを設定する。(以下ではプロジェクトルートの media ディレクトリを設定)\\ '/private/django_proj/media' のような内容で設定される。<code python> 
-MEDIA_ROOT = os.path.join(PROJECT_ROOT, 'media') 
-</code> 
-  - プロジェクトサイトのメディア URL を設定する。(管理サイトのメディア URL と被らないように設定)<code python> 
-MEDIA_URL = '/site_media/' 
-</code> 
-  - 管理サイトのメディア URL を設定する。(プロジェクトサイトのメディア URL と被らないように設定)<code python> 
-ADMIN_MEDIA_PREFIX = '/admin_media/' 
-</code> 
-  - セキュリティキーは django-admin.py が生成したものを利用する。(他のプロジェクトのものをコピーして共有しないこと)<code python> 
-SECRET_KEY = 'y*05eejz)j%+4&c-00i(crrgicz%2_pg+xonohqam0z0@7%f4(' 
-</code> 
-  - **django.template.loaders.filesystem.Loader** テンプレートローダが、プロジェクトルートの templates ディレクトリを検索するように設定する。<code pyhton> 
-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. 
-    os.path.join(PROJECT_ROOT, 'templates'), 
-) 
-</code> 
- 
-===== 修正後のプロジェクト設定ファイル ===== 
-  * 上記をすべて反映させたプロジェクト設定ファイルの内容は以下の通り。<code python> 
-# -*- coding: utf-8 -*- 
-# Django settings for pydev_sample project. 
-import os 
- 
-DEBUG = True 
-#DEBUG = False 
-TEMPLATE_DEBUG = DEBUG 
- 
-ADMINS = ( 
-    # ('Your Name', 'your_email@domain.com'), 
-) 
- 
-MANAGERS = ADMINS 
- 
-# プロジェクトのルートパスを取得 
-PROJECT_ROOT = os.path.abspath(os.path.split(__file__)[0]) 
- 
-DATABASES = { 
-    'default': { 
-        # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. 
-        'ENGINE'    : 'django.db.backends.postgresql_psycopg2', 
-        'NAME'      : 'pydev_sample',   # Or path to database file if using sqlite3. 
-        'USER'      : 'pydev_sample',   # Not used with sqlite3. 
-        'PASSWORD'  : 'test123',        # Not used with sqlite3. 
-        'HOST'      : '',               # Set to empty string for localhost. Not used with sqlite3. 
-        'PORT'      : '',               # Set to empty string for default. Not used with sqlite3. 
-    } 
-} 
- 
-# Local time zone for this installation. Choices can be found here: 
-# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name 
-# 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 = 'Asia/Tokyo' 
- 
-# Language code for this installation. All choices can be found here: 
-# http://www.i18nguy.com/unicode/language-identifiers.html 
-LANGUAGE_CODE = 'ja' 
- 
-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: "/home/media/media.lawrence.com/" 
-MEDIA_ROOT = os.path.join(PROJECT_ROOT, 'media') 
- 
-# 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: "http://media.lawrence.com", "http://example.com/media/" 
-MEDIA_URL = '/site_media/' 
- 
-# 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 = '/admin_media/' 
- 
-# Make this unique, and don't share it with anybody. 
-SECRET_KEY = 'y*05eejz)j%+4&c-00i(crrgicz%2_pg+xonohqam0z0@7%f4(' 
- 
-# List of callables that know how to import templates from various sources. 
-TEMPLATE_LOADERS = ( 
-    'django.template.loaders.filesystem.Loader', 
-    'django.template.loaders.app_directories.Loader', 
-#     'django.template.loaders.eggs.Loader', 
-) 
- 
-MIDDLEWARE_CLASSES = ( 
-    'django.middleware.common.CommonMiddleware', 
-    'django.contrib.sessions.middleware.SessionMiddleware', 
-    'django.middleware.csrf.CsrfViewMiddleware', 
-    'django.contrib.auth.middleware.AuthenticationMiddleware', 
-    'django.contrib.messages.middleware.MessageMiddleware', 
-) 
- 
-ROOT_URLCONF = 'pydev_sample.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. 
-    os.path.join(PROJECT_ROOT, 'templates'), 
-) 
- 
-INSTALLED_APPS = ( 
-    'django.contrib.auth', 
-    'django.contrib.contenttypes', 
-    'django.contrib.sessions', 
-    'django.contrib.sites', 
-    'django.contrib.messages', 
-    # Uncomment the next line to enable the admin: 
-    # 'django.contrib.admin', 
-    # Uncomment the next line to enable admin documentation: 
-    # 'django.contrib.admindocs', 
-) 
-</code> 
  • python/django/django_programming_memo.1439640653.txt.gz
  • 最終更新: 2019/05/18 02:23
  • (外部編集)