728x90

https://docs.djangoproject.com/ko/4.2/intro/tutorial01/

Django 개발 서버는 순수 Python으로 작성된 경량 웹 서버 입니다.

개발 중에만 사용할 수 있도록 되어 있어서 운영환경에서는 다르게 사용해야 한다고 합니다.

장고 프로젝트 사이트에도 "웹 서버가 아닌 웹 프레임워크"라고 설명을 하고 있습니다.

즉 client 호출 대기하는 Web Server(ex Nginx)를 두고 wsgi(Web Server Gateway Interface, ex Gunicorn)를 통해 Django( Was Server )와 연동합니다.

 

정리하면 Django는 와스 서버로서 개발 서버로 동작시 웹서비스 기능을 지원한다고 보면 되겠네요.

 

※ 로컬 프로젝트 프로젝트명 [my_bn1]으로 생성 정보( 업데이트 예정 : book notice 로 DB연동 프로젝트용 )

# 가상화 모듈 설치 
## for mac
python3 -m venv venv
source venv/bin/activate
pip list
pip install django

## 가상화 모듈 설치 ( for windows in vscode bashterminal)
python -m venv venv
source venv/Scripts/activate
pip list
pip install django

; Package    Version
; ---------- -------
; asgiref    3.6.0
; Django     4.2.1
; sqlparse   0.4.4
; tzdata     2023.3

pip freeze > requirements.txt   : 현재 프로젝트에 적용된 라이브러리 정보가 해당 파일에 등록된다.

# 프로젝트 생성하기
## project name "my_bn1" location "." : 현재 폴더 예하에 my_bn1 폴더를 만들고 manage.py가 생성되지만 
   "." 로 폴더를 지정하여 현재 폴더에 manage.py가 생성되도록 한다.
django-admin startproject my_bn1 .
<!-- 
./   
    manage.py  : 프로젝트와 다양한 방법으로 상호작용 하는 커맨드라인의 유틸리티 입니다. manage.py 에
                 대한 자세한 정보는 django-admin and manage.py 에서 확인할 수 있습니다.
    mysite/    : 디렉토리 내부에는 프로젝트를 위한 실제 Python 패키지들이 저장됩니다. 이 디렉토리 내의
                 이름을 이용하여, (mysite.urls 와 같은 식으로) 프로젝트의 어디서나 Python 패키지들을 임포트할 수 있습니다.
        __init__.py  : Python으로 하여금 이 디렉토리를 패키지처럼 다루라고 알려주는 용도의 단순한 빈 
                       파일입니다. 
        settings.py  : 현재 Django 프로젝트의 환경 및 구성을 저장합니다. Django settings에서 환경 
                       설정이 어떻게 동작하는지 확인할 수 있습니다.
        urls.py  : 현재 Django project 의 URL 선언을 저장합니다. Django 로 작성된 사이트의 “목차” 
                   라고 할 수 있습니다. URL dispatcher 에서 URL 에 대한 자세한 내용을 읽어보세요.
        asgi.py  : 현재 프로젝트를 서비스하기 위한 ASGI-호환 웹 서버의 진입점입니다. 자세한 내용은 
                   ASGI를 사용하여 배포하는 방법 를 참조하십시오.
        wsgi.py  : 현재 프로젝트를 서비스하기 위한 WSGI 호환 웹 서버의 진입점입니다. WSGI를 사용하여
                  배포하는 방법를 읽어보세요.  WSGI(Web Server Gateway Interface :위스키 )
        -->

## start python
python manage.py runserver 

## sqlite
python manage.py makemigrations
python manage.py migrate

# folder setting
TEMPLATES = [
    {
...
        'DIRS': [BASE_DIR/'templates'],
...        



# git init
git init
git remote add origin https://github.com/[레파지토리]
-- ex) git remote add origin https://github.com/si0-lab/djangotest1.git

## …or create a new repository on the command line
echo "# djangotest1" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/[레파지토리]
--ex) git remote add origin https://github.com/si0-lab/djangotest1.git
git push -u origin main

## …or push an existing repository from the command line
git remote add origin https://github.com/[레파지토리]
-- ex) git remote add origin https://github.com/si0-lab/djangotest1.git
git branch -M main
git push -u origin main

## …or import code from another repository
You can initialize this repository with code from a Subversion, Mercurial, or TFS project.

# reprojects 
deactivate
rm -rf venv
python -m venv venv
source venv/Scripts/activate
pip install -r requirements.txt

# 장고 설치 확인 ( for windows )
py -m django --version

## 파이썬 가상환경 활성화
### 초기 설정시 ( 기존 사용시에도 사용 가능 )
python3 -m venv venv
source venv/Scripts/activate
### 활성화 명령 파일 실행
venv/Scripts/activate.bat
-- set VIRTUAL_ENV=D:\workspace\test1django\myjan1\venv 가상화 위치 정보가 파일내에 있다.
728x90

+ Recent posts