Djangoの環境構築(ディレクトリ作って、拡張入れるまで)

MacOS上で作業

プロジェクトディレクトリ作成

mkdir -p ~/workspace/django-demo
cd ~/workspace/django-demo

pythonのバージョン切り替え

pyenv install 3.7.2
pyenv local 3.7.2

python仮想環境作成

python -m venv .venv
source .venv/bin/activate
pip install --upgrade pip

パッケージインストール

pip install django==2.2
pip install uwsgi
pip install mysqlclient
pip install django-environ
pip freeze > requirements.txt

開発用パッケージインストール

pip install black
pip install flake8
pip install isort
pip install mypy
pip install pylint
pip install pytest
pip install rope
pip install sphinx
pip freeze > requirements-dev.txt

Djangoの設定用(?)ディレクトリ作成

django-admin startproject config .

.gitignoreを作成

cat << EOS > .gitignore
# Mac
.DS_Store

# Dependency directories
node_modules/

# JetBrains
.idea/

# Atom
.atom/

# VSCode
.vscode/launch.json
.vscode/settings.json

!__init__.py

EOS

curl https://raw.githubusercontent.com/github/gitignore/master/Python.gitignore >> .gitignore

コミット

git init
git add .
git commit -m "initial commit"
git remote add origin git@github.com:watarui/django-demo.git

あとはDockerで(Django + uWSGI + Nginx + MariaDB)な環境を構築して、startapp, makemigrations, migrate, createsuperuserとかしてそれっぽくする。

(poetryとか使ったほうがいいんだろうか…)