python:django:runserver

開発用サーバの起動 (manage.py runserver)

プロジェクトが正常に作成されると開発用サーバを起動して http://127.0.0.1:8000/ にアクセスすることで「The install worked successfully! Congratulations!」のページを表示することができる。

$ cd django_project
$ 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.
March 29, 2020 - 16:19:35
Django version 3.0.4, using settings 'django_project.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.

 http://127.0.0.1:8000/にアクセスした様子。
Django開発サーバ

メモ: 開発用サーバのポートを変更するには、コマンドを以下のようにする。

$ python manage.py runserver 8080

settings.py にてすべてのクライアント Host: ヘッダーを許可するように設定する。

$ cd django_project
$ vi django_project/settings.py
django_project/settings.py
ALLOWED_HOSTS = ['*']

開発サーバーを 0.0.0.0:8000 で起動する。

$ python manage.py runserver 0.0.0.0:8000
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
December 16, 2020 - 06:37:23
Django version 3.1.4, using settings 'django_project.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
  • python/django/runserver.txt
  • 最終更新: 2020/12/16 06:38
  • by ともやん