さくらVPSにて、Django1.3で開発サーバを起動し、アプリを作成する際、テンプレートからCSSが参照できませんでした。しばらく調べて解決したので、備忘録として記録しておきます。
さくらのVPSに入っているPythonは、2.4.3です。
Python 2.4.3 (#1, May 5 2011, 16:39:10) [GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2 Type "help", "copyright", "credits" or "license" for more information.Django1.3をインストールします。
$ wget http://www.djangoproject.com/download/1.3/tarball/ $ tar vxzf Django-1.3.tgz $ cd Django-1.3 $ sudo python setup.py installDjango1.3がインストールされたことを確認します。
Python 2.4.3 (#1, May 5 2011, 16:39:10) [GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import django >>> django.VIRSION (1, 3, 0, 'final', 0)PostGreSQLをインストールします。
# yum install postgresql-server postgresql postgresql-libs postgresql-develpostgresql8.1.23-1がインストールされました。 PostgreSQL関係の操作をpostgresユーザで行います。
{user} su -
{root} su - postgres
{postgres}
データベースを初期化します。
{postgres}$ initdb --encoding=UTF8 --no-locale
・・・
Success. You can now start the database server using:
postmaster -D /var/lib/pgsql/data
or
pg_ctl -D /var/lib/pgsql/data -l logfile start
サーバプロセスの起動と停止のコマンドです。
{postgres}$ pg_ctl -w start // 起動処理終了後プロンプトに戻る
{postgres}$ pg_ctl stop // サーバプロセスの停止
ユーザーを作成します。
{postgres}$ createuser hoge
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) y
Shall the new role be allowed to create more new roles? (y/n) n
CREATE ROLE
psqlでデータベースに接続します。
$ psql postgres hoge
Welcome to psql 8.1.23, the PostgreSQL interactive terminal.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit
postgres=>
$ psql template1 hoge
Welcome to psql 8.1.23, the PostgreSQL interactive terminal.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit
template1=>
終了するには、\qコマンドを実行します。PostGreSQLに用意されているテンプレート用のデータベース「template1」を使います。
パスワードを設定します。
$ psql
Welcome to psql 8.1.23, the PostgreSQL interactive terminal.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit
postgres=# alter user hoge password '**********';
ALTER ROLE
postgres=# \q
PostgerSQLとPythonの接続をします。psycopg2のインストール
$ wget http://initd.org/psycopg/tarballs/PSYCOPG-2-4/psycopg2-2.4.2.tar.gz $ tar vxzf psycopg2-2.4.2.tar.gz $ cd psycopg2-2.4.2 # python setup.py build # python setup.py installはじめての Django アプリ作成の内容を元にアプリを作成していきます。
はじめての Django アプリ作成
http://djangoproject.jp/doc/ja/1.0/intro/tutorial01.html#intro-tutorial01
Djangoのプロジェクトを作成します。
/path/to/django/にて
$ django-admin.py startproject mysiteDjangoアプリケーションを作成します。
/path/to/django/mysite/にて
$ python manage.py startapp polls重要な設定箇所だけを記載します。
/path/to/django/mysite/settings.pyを編集
DATABASES = {
'default': {
'ENGINE': 'postgresql_psycopg2',
'NAME': 'template1',
'USER': 'hoge',
'PASSWORD': '*************',
'HOST': 'localhost',
'PORT': '5432',
}
}
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.admindocs',
'mysite.polls'
)
/path/to/django/mysite/polls/models.pyを編集
from django.db import models
class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
class Choice(models.Model):
poll = models.ForeignKey(Poll)
choice = models.CharField(max_length=200)
votes = models.IntegerField()
admin サイトの有効化/path/to/django/mysite/urls.pyを編集
from django.conf.urls.defaults import patterns, include, url
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^admin/', include(admin.site.urls)),
)
モデルテーブルをデータベース上に作成します。/path/to/django/mysiteにて
$ python manage.py syncdbDjangoを起動
/path/to/django/mysiteにて
$ python manage.py runserver 0.0.0.0:8080管理画面へのアクセスを確認。
次回へ続く。

0 件のコメント:
コメントを投稿