djangoをインストールするまでは、前回の記事
Django(ジャンゴ)をインストールする手順
に記載。
今回はその続き。
・環境設定
コントロールパネルの「ドメイン設定」で
○○○.comを追加
サーバー上のパスは/home/○○○/www/△△△
※△△△にエイリアスを設定。パブリックフォルダとする。
・/home/○○○/local/src/プロジェクト名/プロジェクト名/settings.py
DATABASES=
の設定
INSTALLED_APPS = (
↓コメントアウトを外す
'django.contrib.admin',
'django.contrib.admindocs',
↓追加
'mysite',
↓コメントアウトを外す
'django.contrib.admin',
'django.contrib.admindocs',
↓追加
'mysite',
・/home/○○○/local/src/プロジェクト名/プロジェクト名/urls.py
↓コメントアウトを外す
from django.contrib import admin
admin.autodiscover()
url(r'^admin/', include(admin.site.urls)),
admin.autodiscover()
url(r'^admin/', include(admin.site.urls)),
・SSHでサーバーにログイン
※シェルがcshのままだとデータベースへのデータが作成されない。
「TypeError: decode() argument 1 must be string, not None」
というエラーが出る。これは、ロケールが設定されていないためだ。
下記のコマンドを打つと(None, None)となる。
%python -c 'import locale ; print locale.getdefaultlocale()'
(None, None)
(None, None)
ロケールを設定するには、次のコマンドを実行し、
export LANG=ja_JP.UTF-8
LANGを設定する必要があるが、
※さくらインターネットでは、cshからexportコマンドが使えない。
対応策として、シェルをcshからbashに変更する。
↓シェルを確認するコマンド
%echo $SHELL
/bin/csh #cshと表示される。
/bin/csh #cshと表示される。
↓シェルをbashに変えるコマンド
%chsh -s /usr/local/bin/bash
Password: ※さくらインターネットのパスワードを入力
chsh: user information updated #成功すると表示される。
Password: ※さくらインターネットのパスワードを入力
chsh: user information updated #成功すると表示される。
いったん、ログアウトしてログインし直すと設定が有効になっている。
↓確認コマンド
[○○○@www ~]$ echo $SHELL
/usr/local/bin/bash #bashと表示される。
/usr/local/bin/bash #bashと表示される。
↓シェルをcshに戻すコマンド
[○○○@www ~]$chsh -s /bin/csh
↓念のため、現在のロケールの状態を確認。
[○○○@www ~]$ python -c 'import locale ; print locale.getdefaultlocale()'
(None, None)
(None, None)
↓UTF-8に設定。
[○○○@www ~]$ export LANG=ja_JP.UTF-8
↓変更後の状態を確認。
[○○○@www ~]$ python -c 'import locale ; print locale.getdefaultlocale()'
('ja_JP', 'UTF-8')
('ja_JP', 'UTF-8')
↓bashでの環境変数を設定(cshでは.cshrcに記入されていたもの。bashではスペースのところに=が入る)。
[○○○@www ~]$ export PYTHONPATH=$HOME/local/lib/python:$HOME/local/lib/python/site-packages
[○○○@www ~]$ export PATH=$HOME/local/bin:$PATH
[○○○@www ~]$ export LD_LIBRARY_PATH=$HOME/local/lib
[○○○@www ~]$ export PATH=$HOME/local/bin:$PATH
[○○○@www ~]$ export LD_LIBRARY_PATH=$HOME/local/lib
↓管理画面を設定
[○○○@www ~]$ cd $HOME/local/src/mysite
[○○○@www ~/local/src/mysite]$ python manage.py syncdb
[○○○@www ~/local/src/mysite]$ python manage.py syncdb
↓次のようにDBが設定される
Creating tables ...
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_user_permissions
Creating table auth_user_groups
Creating table auth_user
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table django_admin_log
You just installed Django's auth system, which means you don't have any superusers defined.
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_user_permissions
Creating table auth_user_groups
Creating table auth_user
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table django_admin_log
You just installed Django's auth system, which means you don't have any superusers defined.
↓yesを選択
Would you like to create one now? (yes/no): yes
↓管理者を設定
Username (leave blank to use '○○○'): ユーザー名入力
E-mail address: ××@○○○.com
Password:
Password (again):
Superuser created successfully.
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)
E-mail address: ××@○○○.com
Password:
Password (again):
Superuser created successfully.
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)
↓css,imgの管理画面へのパスを通す
[○○○@www ~]$ mkdir /home/○○○/www/△△△/static
[○○○@www ~]$ cd /home/○○○/www/△△△/static
[○○○@www ~/www/○○○/www/△△△/static]$ ln -s /home/○○○/local/lib/python2.7/site-packages/django/contrib/admin/static/admin/ admin
[○○○@www ~]$ cd /home/○○○/www/△△△/static
[○○○@www ~/www/○○○/www/△△△/static]$ ln -s /home/○○○/local/lib/python2.7/site-packages/django/contrib/admin/static/admin/ admin
これで○○○.com/adminにアクセスするとUsername、Passwordの入力画面になる。
設定したUsername、Passwordで管理画面にログインできる。