Djangoのスタート

pyenv venv　などの仮想環境が存在
https://qiita.com/yagichan1102/items/93c4e043e4c8dbc60cad

venvで仮想環境の構築
※ Python 3系

```python
python -m venv [作成する仮想環境名]
```

venvの削除
参考
https://www.sukerou.com/2020/02/venvpython.html

```
$ ls
heroku1 myenv
$ rm -rf myenv
$ ls
heroku1

$ python3 -m venv myenv
```

vs code　に出現

We noticed a new virtual environment has been created. Do you want to select it for the workspace folder?

djangoファイルの作成

https://qiita.com/soh506/items/12a5df2d19f1c2c792fe

```
$ source myenv/bin/activate
(myenv) ユーザー名-no-MacBook-Pro:heroku1 ユーザー名$ pip install django

Collecting django
  Downloading Django-4.0-py3-none-any.whl (8.0 MB)
     |████████████████████████████████| 8.0 MB 21.6 MB/s 
Collecting asgiref<4,>=3.4.1
  Downloading asgiref-3.4.1-py3-none-any.whl (25 kB)
Collecting sqlparse>=0.2.2
  Downloading sqlparse-0.4.2-py3-none-any.whl (42 kB)
     |████████████████████████████████| 42 kB 2.0 MB/s 
Collecting backports.zoneinfo; python_version < "3.9"
  Downloading backports.zoneinfo-0.2.1.tar.gz (74 kB)
     |████████████████████████████████| 74 kB 6.6 MB/s 
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Building wheels for collected packages: backports.zoneinfo
  Building wheel for backports.zoneinfo (PEP 517) ... done
  Created wheel for backports.zoneinfo: filename=backports.zoneinfo-0.2.1-cp38-cp38-macosx_10_14_x86_64.whl size=49349 sha256=9aa5b746d87805b83c7ac9132100514f7f38c8ed877e362d9b6b4faa795033e9
  Stored in directory: /Users/ユーザー名/Library/Caches/pip/wheels/c7/de/cc/c405827ed64f81b56142f1e0075a970b2731b00d21983d54fb
Successfully built backports.zoneinfo
Installing collected packages: asgiref, sqlparse, backports.zoneinfo, django
Successfully installed asgiref-3.4.1 backports.zoneinfo-0.2.1 django-4.0 sqlparse-0.4.2

WARNING: You are using pip version 20.2.3; however, version 21.3.1 is available.
You should consider upgrading via the '/Users/ユーザー名/Projects/heroku1/myenv/bin/python3 -m pip install --upgrade pip' command.
```

pipのupgrade

```
(myenv) ユーザー名-no-MacBook-Pro:heroku1 ユーザー名$ python3 -m pip install --upgrade pip
Collecting pip
  Downloading pip-21.3.1-py3-none-any.whl (1.7 MB)
     |████████████████████████████████| 1.7 MB 7.2 MB/s 
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 20.2.3
    Uninstalling pip-20.2.3:
      Successfully uninstalled pip-20.2.3
Successfully installed pip-21.3.1
(myenv) ユーザー名-no-MacBook-Pro:heroku1 ユーザー名$ 
```

プロジェクトファイルの作成

```
(myenv) ユーザー名-no-MacBook-Pro:heroku1 ユーザー名$ django-admin startproject config .
```

構成

```
heroku1
├── papersns
│   ├── __init__.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
├── manage.py
└── myenv
```

仮想環境ないのpythonを使用
以下の画像部分をクリックして選択できる

![スクリーンショット 2021-12-27 2.10.59.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2434937/dcbb2ca1-a461-80a8-1215-509eecd90ec5.png)


Djangoの実行

虫▷ボタンをクリック→ create a launch.json file クリック→Run and Debug をクリック

Djangoを選択して実行
![スクリーンショット 2021-12-27 2.22.03.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2434937/79b3f43d-07b2-6623-31b1-13587896575d.png)

テスト　サーバー　成功！

```
(myenv) ユーザー名-no-MacBook-Pro:heroku1 ユーザー名$  cd /Users/ユーザー名/Projects/heroku1 ; /usr/bin/env /Users/ユーザー名/Projects/heroku1/myenv/bin/python /Users/ユーザー名/.vscode/extensions/ms-python.python-2021.12.1559732655/pythonFiles/lib/python/debugpy/launcher 58187 -- /Users/ユーザー名/Projects/heroku1/manage.py runserver 
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).

You have 18 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.
December 26, 2021 - 17:19:05
Django version 4.0, using settings 'papersns.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
```