본문 바로가기

Python

Start Django project with Python DI manager poetry

반응형

Poetry 설치

공식 문서 참고 

 

Introduction | Documentation | Poetry - Python dependency management and packaging made easy

Using alternative installation methods will make Poetry always use the Python version for which it has been installed to create virtualenvs. So, you will need to install Poetry for each Python version you want to use and switch between them.

python-poetry.org

프로젝트 디렉터리 생성

mkdir goboard

DI manager poetry 설정

poetry  파일 생성

cd goboard
touch pyproject.toml

poetry 설정 (python & django 추가)

pyproject.toml

[tool.poetry]
name = "goboard"
version = "0.1.0"
description = ""
authors = ["goboard kim<demo@demo.com>"]

[tool.poetry.dependencies]
python = "^3.9.1"

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

Django Dependency 추가 (Django)

추가 및 설치는 poetry 설정파일에 추가 하는 방법과 poetry 명령어를 통해 추가 하는 방법이 있다.

설정 파일 추가

pyproject.toml

[tool.poetry]
name = "goboard"
version = "0.1.0"
description = ""
authors = ["goboard kim<demo@demo.com>"]

[tool.poetry.dependencies]
python = "^3.9.1"
Django = "3.1.3"

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

Poetry 커맨드를 통해 추가

poetry add django==3.1.3

 

Django 프로젝트 생성

cd goboard

django-admin startproject config .

Django App 생성 (goboo)

cd goboard

django-admin startapp goboo

 

Django 프로젝트 결과

goboard
├── README.md
├── config
│   ├── __init__.py
│   ├── __pycache__
│   ├── asgi.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
├── db.sqlite3
├── goboo
│   ├── __init__.py
│   ├── admin.py
│   ├── apps.py
│   ├── migrations
│   ├── models.py
│   ├── tests.py
│   └── views.py
├── manage.py
├── poetry.lock
└── pyproject.toml

Django 서버 실행 오류 해결 방법

python manage.py runserver 실행시 poetry 가 django 를 인식 못할 경우 

poetry run python manage.py migrate

poetry run python manage.py runserver 

or

python manage.py runserver
반응형

'Python' 카테고리의 다른 글

Prefect  (0) 2023.11.08
python data class  (0) 2020.01.19
Python application with Docker Image build and Run  (0) 2019.07.14
python file line read and set  (0) 2019.06.15
pymongo usage  (0) 2019.06.08