LoginSignup
0
1

More than 3 years have passed since last update.

復習 Django チュートリアル :コードをいじるまでの環境設定

Last updated at Posted at 2018-12-22

目的

現段階(チュートリアル(4))までを復習して、自分で使いこなせるという実感を持ちたい。入力するコマンドと最低限の説明のみで整理したい。もうすでにどんなコマンド使ったか忘れてしまっているので…。作業場はtestdirectory、プロジェクト名は littleproject、アプリ名はlitteleappとする。(2019/09/18 改訂)

環境

ThinkPad T440p
Ubuntu Linux 18.04 日本語 Remix
Python 3.6.7
pip 18.1
Django 2.1.4

pip をインストールする

Debian/Ubuntu
Python 2:
$ sudo apt install python-pip
Python 3:
$ sudo apt install python3-venv python3-pip

参考 : Installing pip/setuptools/wheel with Linux Package Managers

参考 : よく使うpipコマンド

上記でvenvをインストールしたのでvirtualenvは不要なはず (2019/09/18 改訂)
virtualenv をインストールする

$ sudo -H pip install virtualenv

以下は -H つけなかったら出てくる表示。
>The directory '/home/***/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.

-H つけると出ない。何の意味があるのか良くわかっていないが、つけたほうが精神衛生上いい。

参考 : sudo -Hと環境変数($PATH)ではまった話

Django をインストールする

$ mkdir testdirectory
    # testdirectory 作成
$ cd testdirectory
    # testrirectory に移動
$ python3 -m venv env
    # testdirectory に venv 環境を作る
    # env という名前のディレクトリが作成される
$ source bin/activate
    # venv 起動
(env)$ pip install Django
    # (env)$ は venv 上でやってますよの証
    # Django がインストールされる

Django で project をつくる

以下$の前に(env)が付く= venv 上で作業する
$ django-admin startproject littleproject
    # littleproject ディレクトリと manage.py が作成される
    # ファイル構成は以下の通り
littleproject
├── littleproject
│   ├── __init__.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
└── manage.py
$ python manage.py runserver
    # サーバーが立ち上がる
    # 127.0.0.1:8000 にアクセスするとロケットの絵が表示される

Django で application をつくる

$ python manage.py startapp littleapp
    # littleapp と db.sqlite がつくられる
    # ファイル構成は以下の通り

littleproject
├── db.sqlite3
├── littleapp
│   ├── __init__.py
│   ├── admin.py
│   ├── apps.py
│   ├── migrations
│   │   └── __init__.py
│   ├── models.py
│   ├── tests.py
│   └── views.py
├── littleproject
│   ├── __init__.py
│   ├── __pycache__
│   │   ├── __init__.cpython-36.pyc
│   │   ├── settings.cpython-36.pyc
│   │   ├── urls.cpython-36.pyc
│   │   └── wsgi.cpython-36.pyc
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
└── manage.py

以上がコードをいじるまでの環境設定。

0
1
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
0
1