Cookiecutter Djangoとは、DjangoベースのWebアプリケーション作成用フレームワーク。
これを使ってWebアプリを作成する過程の記録をブログにまとめます。
Rice Hacker(仮名)という、世界の日本食レストラン検索サービスを作ります。
pipとvirtualenvはインストールしておいて下さい。
使用PCはMac。Virtualenvで仮想環境構築。データベースはPostgres.appを使用。
mkdir service
serviceフォルダの中にPostgres.appのデータ格納用フォルダとプロジェクトフォルダを作成。
cd ./service mkdir data mkdir rice_hacker
rice_hackerフォルダに移動し、仮想環境を作成。
cd ./rice_hacker virtualenv env_rice_hacker
仮想環境下に入る。
source ./env_rice_hacker/bin/activate
Cookiecutterをインストール
pip install cookiecutter
Cookiecutter Djangoをインストール
cookiecutter https://github.com/pydanny/cookiecutter-django
project_name [Project Name]: Rice Hacker project_slug [rice_hacker]: author_name [Daniel Roy Greenfeld]: Taro email [you@example.com]: taro@example description [A short description of the project.]: Japanese restaurants foods sharing service . domain_name [example.com]: ricehacker.com version [0.1.0]: 0.0.1 timezone [UTC]: America/Vancouver use_whitenoise [y]: y use_celery [n]: n use_mailhog [n]: n use_sentry [y]: y use_pycharm [n]: n windows [n]: n use_docker [y]: n use_heroku [n]: y use_compressor [n]: n Select postgresql_version: 1 - 10.3 2 - 10.2 3 - 10.1 4 - 9.6 5 - 9.5 6 - 9.4 7 - 9.3 Choose from 1, 2, 3, 4 [1]: 4 Select js_task_runner: 1 - Gulp 2 - Grunt 3 - None Choose from 1, 2, 3, 4 [1]: 3 custom_bootstrap_compilation [n]: n Select open_source_license: 1 - MIT 2 - BSD 3 - GPLv3 4 - Apache Software License 2.0 5 - Not open source Choose from 1, 2, 3, 4, 5 [1]: 1 keep_local_envs_in_vcs [y]: y
全て設定するとプロジェクトの雛形が完成。次はCookiecutter Djangoで必要なライブラリ群をインストール。
pip install -r requirements/local.txt
次はデータベースの作成。Postgres.appにて、新規サーバーを立ち上げ、initializeしておく。
project_slugと同じ名前のデータベースを作成し、migrate。
createdb rice_hacker python manage.py migrate
アプリケーションを起動してみます。
python manage.py runserver
ブラウザで127.0.0.1:8000にアクセスすると、以下のような画面となります。
これが表示されれば成功です。次回以降、appを作成していきます。