LoginSignup
3
5

More than 5 years have passed since last update.

Djangoのtemplateを見てみる。

Posted at

PythonのDjango1.9のProject templateを試す。

Djangoの構成の勉強と思い、Githubで検索してみたら、面白そうなのがあったので試してみました。
djangoのprojectのtemplateを元に、startprojectをするのは初めて。

参照Github(英語)Sam's Django Project Template

もともとはこういうことらしい。
It is based on the project_template shipped with stable/1.5.x and modified for Django 1.9.

特徴は、

  1. 開発環境と本番環境を想定して設定されている
  2. debugツールバーが設定されている。
  3. Dはpostgresql。(9.5で試しました)
  4. wsgi(本番の
  5. setteing.pyも本番用、開発用で分かれている。
  6. Grappelli(adminページCMS強化ツールって感じ)<= これが面白そう。

準備

postgresqlのインストール

sudo apt-get install postgresql-9.5
sudo apt-get install  postgresql-server-dev-9.5
  • 最初server-devを入れてなかったのでこのあとのpip install でエラーになった。

手順にしたがって実施

virtualenv設定(以降、virtualenvで実施)

$ virtualenv env
$ source env/bin/activate

pip install

$ pip install -r https://raw.github.com/sjkingo/django-project-template/master/requirements.txt
$ pip install -r https://raw.github.com/sjkingo/django-project-template/master/requirements-dev.txt

こちらで、この3つと1つが入る。
1. Django
2. django-grappelli
3. psycopg2
1. django-debug-toolbar

django projectの作成

django-admin.py startproject --template https://github.com/sjkingo/django-project-template/archive/master.zip $PROJECT_NAME

あっさり実行完了して、これらができました。

$ ls foo
README.md    manage.py             requirements.txt  urls.py
__init__.py  requirements-dev.txt  settings          wsgi.py

pipバージョンをfreezeして、manage.pyに実行権限をつけました。

$ cd $PROJECT_NAME
$ pip freeze > requirements.txt
$ rm -f README.md
$ chmod +x manage.py

ここまでやって、./manage.py runserverすると、DBエラーになる。
だってまだ設定してないもん。。。

Postgresqlの設定

めったにやるもんでもないから、いつもわすれがち。

インストールしたあとにできているのは、
デフォルトユーザ:postgres

DjangoでのPostgresqlの設定、こちらにありますが、
自分でもメモ作りました。

 systemctl enable postgresql-9.5

データベース作成 as hoge

postgres=# create database hoge;
CREATE DATABASE
postgres=# \l
postgres=# \l
                              List of databases
Name Owner Encoding Collate Ctype Access privileges
hoge postgres UTF8 ja_JP.UTF-8 ja_JP.UTF-8
postgres postgres UTF8 ja_JP.UTF-8 ja_JP.UTF-8
template0 postgres UTF8 ja_JP.UTF-8 ja_JP.UTF-8 =c/postgres +
postgres=CTc/postgres
template1 postgres UTF8 ja_JP.UTF-8 ja_JP.UTF-8 =c/postgres +
postgres=CTc/postgres

(4 rows)

DBユーザ as piyo 作成してパスワード設定。

$ createuser -a piyo
postgres=# \password piyo
Enter new password: 
Enter it again: 

djangoのsettingsに設定

settings/base.pyに、ネームなど設定

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'hoge',
        'USER': 'piyo',
        'PASSWORD': 'piyo',
        'HOST' : '127.0.0.1',
        'PORT' : 5432,
    }
}

簡単なmodelを設定。

爆速RESTのページから、モデルを設定して管理画面設定まで追加。

少しgrappelli風な管理画面が見えるようになりました。

Screenshot from 2016-05-08 21-29-20.png

まずはここまで。

3
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
5