以下の公式のDjangoチュートリアルをやってみる。
https://docs.djangoproject.com/ja/3.0/intro/tutorial01/
■チュートリアルの内容
章立て
その1〜7までの7つの章が存在する。
その1をやってみる
Djangoのバージョンを確認したところ、以前にインストール済みであり、バージョンは2.2だった。
3.0がリリースされており、チュートリアルもデフォルトは3.0を前提としているので、最新版にバージョンUPする。
(2020/4/22時点)
$ python -m django --version 2.2 $ pip install Django -U Requirement already satisfied, skipping upgrade: sqlparse>=0.2.2 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from Django) (0.3.0) Requirement already satisfied, skipping upgrade: pytz in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from Django) (2019.1) Collecting asgiref~=3.2 Downloading asgiref-3.2.7-py2.py3-none-any.whl (19 kB) Installing collected packages: asgiref, Django Attempting uninstall: Django Found existing installation: Django 2.2 Uninstalling Django-2.2: Successfully uninstalled Django-2.2 Successfully installed Django-3.0.5 asgiref-3.2.7 $ python -m django --version 3.0.5
プロジェクトを作成する
$ django-admin startproject mysite $ tree mysite mysite ├── manage.py └── mysite ├── __init__.py ├── asgi.py ├── settings.py ├── urls.py └── wsgi.py 1 directory, 6 files
開発用サーバーを起動する
$ cd mysite $ python manage.py runserver Watching for file changes with StatReloader Performing system checks... System check identified no issues (0 silenced). You have 17 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions. Run 'python manage.py migrate' to apply them. April 21, 2020 - 11:27:47 Django version 3.0.5, using settings 'mysite.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C.
curlで確認
$ curl -I "http://127.0.0.1:8000/" HTTP/1.1 200 OK Date: Tue, 21 Apr 2020 11:39:00 GMT Server: WSGIServer/0.2 CPython/3.7.3 Content-Type: text/html X-Frame-Options: DENY Content-Length: 16351 X-Content-Type-Options: nosniff
ブラウザでhttp://127.0.0.1:8000/を開くと以下のような画面が表示される。
Polls アプリケーションの雛形を作成する
$ python manage.py startapp polls $ tree polls polls ├── __init__.py ├── admin.py ├── apps.py ├── migrations │ └── __init__.py ├── models.py ├── tests.py └── views.py
以上でその1は終了