$ git clone https://github.com/yyuu/pyenv.git ~/.pyenv
$ export PYENV_ROOT="$HOME/.pyenv"
$ export PATH="$PYENV_ROOT/bin:$PATH"
$ eval "$(pyenv init -)"
Check out the latest python
$ pyenv install --list
Install the latest python
$ pyenv install 3.8.1
$ pyenv local 3.8.1
$ python -V
Python 3.8.1
$ pip install pipenv
When installing with pipenv, it usually goes to ~ / .local / share / virtualenvs /
, but it should go to .venv
directly under the project. .venv
is created automatically when you enter the virtual environment.
$ echo 'export PIPENV_VENV_IN_PROJECT=1' >> ~/.bash_profile
Specifies the python version to use within the pipenv virtual environment
$ pipenv --python 3.8
Enter the virtual environment.
$ pipenv shell
django
│── Pipfile
│── Pipfile.lock
└── .venv
$ pipenv install django django-bootstrap4
$ pipenv install --dev django-debug-toolbar django-webpack-loader #Development environment only
By default, pipenv cannot install pre-release packages. You need to add the settings to your Pipfile as follows:
Pipfile
[pipenv]
allow_prereleases = true
Create a project in the virtual environment of pipenv
$ django-admin startproject config .
django
│── config
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
│── Pipfile
│── Pipfile.lock
├── .venv
└── manage.py
django
├── config
│ ├── __init__.py
│ ├── settings
│ │ ├── __init__.py
│ │ ├── base.py #Common settings
│ │ ├── production.py #Settings that you want to apply only to the production environment
│ │ ├── development.py #Settings that you want to apply only to the development environment
│ │ └── test.py #Settings that you want to apply only to the test
│ ├── urls.py
│ └── wsgi.py
│── Pipfile
│── Pipfile.lock
├── .venv
└── manage.py
Fixed BASE_DIR
in base.py because the directory has changed
base.py
- BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+ BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
production.py
#Settings that you want to apply only to the production environment
from .base import *
DEBUG = True
development.py
#Settings that you want to apply only to the development environment
from .base import *
DEBUG = False
python manage.py startapp test_app
django
├── config
│── Pipfile
│── Pipfile.lock
├── .venv
│── manage.py
└── test_app
├── __init__.py
├── admin.py
├── apps.py
├── migrations
├── models.py
├── tests.py
└── views.py
base.py
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
+ 'DIRS': [os.path.join(BASE_DIR, "templates")],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
django
├── config
│── Pipfile
│── Pipfile.lock
├── .venv
│── manage.py
│── templates
│ └── test_app
└── test_app
├── __init__.py
├── admin.py
├── apps.py
├── migrations
├── models.py
├── tests.py
└── views.py
https://fclef.jp/20191103/ https://studygyaan.com/django/best-practice-to-structure-django-project-directories-and-files
Recommended Posts