본문 바로가기
BE/Python & Django REST API

[Django REST API] 5. Creating a Django app

by 건빵거늬 2021. 12. 18.
1. Create Python Virtual Environment
2. Install required Python packages
3. Create new Django project & app
4. Enable app in Django settings file
5. Test and commit

1. Create Python Virtual Environment

vagrant develop server에 virtual environment 설정하기

(1) pipenv 사용법

https://python-guide.readthedocs.io/en/latest/dev/virtualenvs/

 

Pipenv & Virtual Environments — The Hitchhiker's Guide to Python

 

docs.python-guide.org

(2) 실습

venv 파일 만들기

  • -m mod : run library module as a script (terminates option list)
  • venv 사용법: venv [-h] [--system-site-packages] [--symlinks | --copies] [--clear] [--upgrade] [--without-pip] [--prompt PROMPT] ENV_DIR [ENV_DIR ...]

ENV_DIR을 ~/env로 해주는 이유: vagrant server의 env파일이 저장되는 디렉토리는 local machine과 synchronized 되지 말아야한다.

왜냐하면 vagrant server를 새로 만드는 경우가 생길 때 env 디렉토리는 local machine과 분리 시켜야 깨끗한 상태에서 시작할 수 있기 때문이다.

 

virtualenv activate, deactivate 하는 방법

 

2. Install required Python packages

목표: django와 django rest framework 설치하기

(1) requirements.txt 작성

(2) 설치하기

3. Create new Django project & app

4. Enable app in Django settings file

5. Test and commit

(1) 서버실행

port 8000으로 실행하는 이유: Vagrantfile 에서 guest를 port 8000으로 열어뒀기 때문

(2) 서버 접속

127.0.0.1:8000 으로 접속하는 이유: Vagrantfile 에서 guest port 8000을 host port 8000으로 연결해뒀기 때문

(3) commit

댓글