Debian 11.2にDjango3.2 をインストールする
環境情報
osバージョンを確認します
# cat /etc/debian_version
11.2
Django 3.2インストールの方法
1.必要なパッケージをインストールします
# apt -y install python3-virtualenv
2.Virtualenv 環境を作成します
created virtual environment CPython3.9.2.final.0-64 in 2730ms
creator CPython3Posix(dest=/root/venv, clear=False, no_vcs_ignore=False, global=False)
seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/root/.local/share/virtualenv)
added seed packages: pip==20.3.4, pkg_resources==0.0.0, setuptools==44.1.1, wheel==0.34.2
activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator
created virtual environment CPython3.9.2.final.0-64 in 2730ms
creator CPython3Posix(dest=/root/venv, clear=False, no_vcs_ignore=False, global=False)
seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/root/.local/share/virtualenv)
added seed packages: pip==20.3.4, pkg_resources==0.0.0, setuptools==44.1.1, wheel==0.34.2
activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator
created virtual environment CPython3.9.2.final.0-64 in 2730ms creator CPython3Posix(dest=/root/venv, clear=False, no_vcs_ignore=False, global=False) seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/root/.local/share/virtualenv) added seed packages: pip==20.3.4, pkg_resources==0.0.0, setuptools==44.1.1, wheel==0.34.2 activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator
3.Django をインストールします
仮想環境を有効にします
# cd ~/venv
root@debian:~/venv# source bin/activate
(venv) root@debian:~/venv#
# pip install django==3.2
略
Installing collected packages: sqlparse, pytz, asgiref, django
Successfully installed asgiref-3.4.1 django-3.2 pytz-2021.3 sqlparse-0.4.2
# cd ~/venv
root@debian:~/venv# source bin/activate
(venv) root@debian:~/venv#
# pip install django==3.2
略
Installing collected packages: sqlparse, pytz, asgiref, django
Successfully installed asgiref-3.4.1 django-3.2 pytz-2021.3 sqlparse-0.4.2
# cd ~/venv root@debian:~/venv# source bin/activate (venv) root@debian:~/venv# # pip install django==3.2 略 Installing collected packages: sqlparse, pytz, asgiref, django Successfully installed asgiref-3.4.1 django-3.2 pytz-2021.3 sqlparse-0.4.2
4.Djangoバージョンを確認します
# django-admin --version
3.2
# django-admin --version
3.2
# django-admin --version 3.2
5.仮想環境virtualenv からログアウト
(venv) root@debian:~/venv# deactivate
root@debian:~/venv#
6.テストプログラムを作成します
root@debian:~/venv# cd ~/venv
root@debian:~/venv# source bin/activate
(venv) root@debian:~/venv# django-admin startproject demoprj
(venv) root@debian:~/venv# cd demoprj
(venv) root@debian:~/venv/demoprj#
root@debian:~/venv# cd ~/venv
root@debian:~/venv# source bin/activate
(venv) root@debian:~/venv# django-admin startproject demoprj
(venv) root@debian:~/venv# cd demoprj
(venv) root@debian:~/venv/demoprj#
root@debian:~/venv# cd ~/venv root@debian:~/venv# source bin/activate (venv) root@debian:~/venv# django-admin startproject demoprj (venv) root@debian:~/venv# cd demoprj (venv) root@debian:~/venv/demoprj#
7.データベースを設定します((デフォルトは SQLite))
(venv) root@debian:~/venv/demoprj# python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
略
Applying auth.0012_alter_user_first_name_max_length... OK
Applying sessions.0001_initial... OK
(venv) root@debian:~/venv/demoprj# python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
略
Applying auth.0012_alter_user_first_name_max_length... OK
Applying sessions.0001_initial... OK
(venv) root@debian:~/venv/demoprj# python manage.py migrate Operations to perform: Apply all migrations: admin, auth, contenttypes, sessions Running migrations: Applying contenttypes.0001_initial... OK Applying auth.0001_initial... OK Applying admin.0001_initial... OK 略 Applying auth.0012_alter_user_first_name_max_length... OK Applying sessions.0001_initial... OK
管理者ユーザーを作成します
# python manage.py createsuperuser
Username (leave blank to use 'root'): arkgame
Email address: contact@arkgame.com
Password: #パスワードを入力
Password (again): #確認パスワードを入力
Superuser created successfully.
# python manage.py createsuperuser
Username (leave blank to use 'root'): arkgame
Email address: contact@arkgame.com
Password: #パスワードを入力
Password (again): #確認パスワードを入力
Superuser created successfully.
# python manage.py createsuperuser Username (leave blank to use 'root'): arkgame Email address: contact@arkgame.com Password: #パスワードを入力 Password (again): #確認パスワードを入力 Superuser created successfully.
全てホストからもアクセスを許可します
# vi demoprj/settings.py
28行目
修正前
ALLOWED_HOSTS = []
修正後
ALLOWED_HOSTS = ['*']
# vi demoprj/settings.py
28行目
修正前
ALLOWED_HOSTS = []
修正後
ALLOWED_HOSTS = ['*']
# vi demoprj/settings.py 28行目 修正前 ALLOWED_HOSTS = [] 修正後 ALLOWED_HOSTS = ['*']
8.サーバーを起動します
# 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 26, 2021 - 02:20:10
Django version 3.2, using settings 'demoprj.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
# 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 26, 2021 - 02:20:10
Django version 3.2, using settings 'demoprj.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
# 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 26, 2021 - 02:20:10 Django version 3.2, using settings 'demoprj.settings' Starting development server at http://0.0.0.0:8000/ Quit the server with CONTROL-C.
7.Django動作確認
Webブラウザを起動し、[http://192.168.71.144:8000/] にアクセスします。
「The install worked successfully! Congratulations!」が表示されます
管理画面
http://192.168.71.144:8000/admin
「Username」、「Password」を入力し、「Login」を押下します
「Django administration」画面が表示されます
Webブラウザを起動し、[http://192.168.71.144:8000/] にアクセスします。
「The install worked successfully! Congratulations!」が表示されます
管理画面
http://192.168.71.144:8000/admin
「Username」、「Password」を入力し、「Login」を押下します
「Django administration」画面が表示されます
Webブラウザを起動し、[http://192.168.71.144:8000/] にアクセスします。 「The install worked successfully! Congratulations!」が表示されます 管理画面 http://192.168.71.144:8000/admin 「Username」、「Password」を入力し、「Login」を押下します 「Django administration」画面が表示されます