[Memo] Django development environment

Put pyenv

$ git clone https://github.com/yyuu/pyenv.git ~/.pyenv
$ export PYENV_ROOT="$HOME/.pyenv"
$ export PATH="$PYENV_ROOT/bin:$PATH"
$ eval "$(pyenv init -)"

Put the latest python

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

Insert pipenv

$ 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

Package management

$ 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

Django project

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

Split settings file

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

Application creation

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

Put together a template

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

Put together static

Put your application together

reference

https://fclef.jp/20191103/ https://studygyaan.com/django/best-practice-to-structure-django-project-directories-and-files

Recommended Posts

[Memo] Django development environment
Django environment development on Windows 10
[MEMO] [Development environment construction] Python
Ubuntu18.04 Development environment creation memo
django project development environment construction
[MEMO] [Development environment construction] wine
Development environment load measurement memo
[For beginners] Django -Development environment construction-
[MEMO] [Development environment construction] Jupyter Notebook
Vim + Python development environment setting memo
Emacs Python development environment construction memo
Ubuntu Desktop 20.04 development environment construction memo
Django environment construction
Django Learning Memo
[Memo] Build a development environment for Django + Nuxt.js with Docker
django tutorial memo
django environment construction
Build Django + NGINX + PostgreSQL development environment with Docker
heroku deployment memo (Django)
Django project environment construction
ConoHa environment construction memo
Until Django application creation by terminal (development environment)
Django memo # 1 from scratch
Python development environment construction
[Python] Build a Django development environment with Docker
About Python development environment
Build a Django development environment with Doker Toolbox
python2.7 development environment construction
BigGorilla environment construction memo
Development environment in Python
From 0 to Django development environment construction to basic operation
A memo to create a virtual environment (venv) before Django
Build a Django development environment using pyenv-virtualenv on Mac
Build a development environment with Poetry Django Docker Pycharm
Prepare Django development environment using homebrew on MacOSX Mavericks (10.9)
Minimal website environment with django
Development environment suitable for ArcPy
Django Getting Started: 1_Environment Building
[Memo] Construction of cygwin environment
Docker + Django + React environment construction
Anaconda3 × Pycharm environment construction memo
Organize your Python development environment
[ev3dev × Python] Build ev3dev development environment
(Note) Django in Vagrant environment
[For organizing] Python development environment
[Day 1] Prepare Django's development environment
[Learning memo] Django command summary
Django + MongoDB development environment maintenance (in the middle of writing)
[Django] Build a Django container (Docker) development environment quickly with PyCharm
[Django] Memo to create an environment of Django + MySQL + Vue.js [Python]
Test Driven Development with Django Part 3
Django admin screen reverse lookup memo
Mac + Eclipse (PyDev) + Django environment construction
WEB application development using Django [Django startup]
Python environment construction memo on Windows 10
Test Driven Development with Django Part 6
WEB application development using Django [Application addition]
Prepare Python development environment on Ubuntu
Python practice_Virtual environment setup ~ Django installation
Django cannot be installed in the development environment of pipenv + pyenv
[Personal memo] Python virtual environment command memo