LoginSignup
5
4

More than 5 years have passed since last update.

Djangoをpyenv+pyenv-virtualenv環境で動かすまで()

Last updated at Posted at 2018-04-14

Djangoを動かそう

時間がない人向けの記事です。
以下のコマンドを実行していけばいける。

以下のものはあらかじめインストールしておこう。

  • pyenv
  • pyenv-virtualenv

入っていない人は以下の記事でpythonを入れておこう。

Ubuntuで主要言語達の最新Ver.をインストールする方法まとめ

コマンド

terminal
# python3.6.5をインストール
$ pyenv install 3.6.5

# 仮想環境を作る
$ pyenv virtualenv 3.6.5 hoge-env

# お好きな場所にプロジェクトファイルを作る
$ mkdir hoge-proj
# プロジェクトファイルに移動
$ cd hoge-proj

# プロジェクトの環境を先ほど作った仮想環境に設定
$ pyenv local hoge-env

# Djangoをインストール
$ pip install django

# Djangoでプロジェクトを作る

# 現在の作業ディレクトリにDjangoをインストールする
$ django-admin startproject hogesite .
# hoge-proj
# ├── manage.py
# └── hogesite
#     ├── __init__.py
#     ├── settings.py
#     ├── urls.py
#     └── wsgi.py

# -----------------------------------

# hogesiteディレクトリを作成し、そこにDjangoをインストールする場合
$ django-admin startproject hogesite
# hoge-proj
# └── hogesite
#     ├── manage.py
#     └── hogesite
#         ├── __init__.py
#         ├── settings.py
#         ├── urls.py
#         └── wsgi.py

$ cd hogesite

# -----------------------------------

# プログラムを起動
$ python manage.py runserver

起動確認

アプリ起動後以下のURLにアクセスする。
localhost:8000

django-startapp.png

この画面が表示されたらOK

5
4
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
5
4