(06.15) 수정됨.
콘솔창 실행하기
(윈도우 환경 기준)
"윈도우 키" + "R" 버튼을 눌러 "실행" 프로그램에 "cmd"를 입력하면 "C:\Windows\system32\cmd.exe"가 실행된다.
이 글에서 입력하는 명령어는 모두 cmd 콘솔 창에 입력하는 것이다.
장고 패키지 설치하기
"python -m pip install django" 명령으로 파이썬 장고 패키지를 설치할 수 있다.
>> python -m pip install django
또는
>> pip install django
명령어를 실행하면 다음과 같이 장고 라이브러리를 설치한다.
(django-sample) C:\WhiteSeolpyo\django-sample>python -m pip install django
Collecting django
Downloading django-5.2.3-py3-none-any.whl.metadata (4.1 kB)
Collecting asgiref>=3.8.1 (from django)
Using cached asgiref-3.8.1-py3-none-any.whl.metadata (9.3 kB)
Collecting sqlparse>=0.3.1 (from django)
Using cached sqlparse-0.5.3-py3-none-any.whl.metadata (3.9 kB)
Collecting tzdata (from django)
Using cached tzdata-2025.2-py2.py3-none-any.whl.metadata (1.4 kB)
Downloading django-5.2.3-py3-none-any.whl (8.3 MB)
---------------------------------------- 8.3/8.3 MB 10.1 MB/s eta 0:00:00
Using cached asgiref-3.8.1-py3-none-any.whl (23 kB)
Using cached sqlparse-0.5.3-py3-none-any.whl (44 kB)
Using cached tzdata-2025.2-py2.py3-none-any.whl (347 kB)
Installing collected packages: tzdata, sqlparse, asgiref, django
Successfully installed asgiref-3.8.1 django-5.2.3 sqlparse-0.5.3 tzdata-2025.2
장고 프로젝트 생성방법
"django-admin startproject {설정파일 폴더명} {프로젝트 폴더명}" 명령을 입력하면 장고 프로젝트 파일을 생성한다.
프로젝트 폴더명에 "."을 입력한다면 현재 위치하고 있는 폴더에 파일을 생성한다.
예를 들어 "django_sample"이라는 폴더 안에 장고 프로젝트를 생성하고, 설정 파일은 "config"라는 폴더에 넣어두고 싶다면 다음과 같이 입력하면 된다.
윈도우 환경이기 때문에 현재 위치 파일 목록을 호출하기 위해 "dir" 명령을 사용한다.
(django-sample) C:\WhiteSeolpyo\django-sample>dir
C:\WhiteSeolpyo\django-sample 디렉터리
2025-06-15 오후 03:23 <DIR> .
2025-06-15 오후 03:23 <DIR> ..
(django-sample) C:\WhiteSeolpyo\django-sample>django-admin startproject config django_sample
(django-sample) C:\WhiteSeolpyo\django-sample>dir
C:\WhiteSeolpyo\django-sample 디렉터리
2025-06-15 오후 03:23 <DIR> .
2025-06-15 오후 03:23 <DIR> ..
2025-06-15 오후 03:23 <DIR> django_sample
파일 트리
장고 프로젝트가 최초로 생성되면 트리 구조는 다음과 같다.
...
|- django_sample
|- manage.py
|- config
|- __init__.py
|- asgi.py
|- settings.py
|- urls.py
|- wsgi.py
프로젝트 실행 방법
"python manage.py runserver" 명령을 통해 장고 프로젝트를 실행해볼 수 있다.
manage.py를 호출하는 것이므로 manage.py와 같은 위치로 이동할 필요가 있다.
최초 실행시 migrate를 진행하라는 경고문이 나오는데, 아무런 세팅이 되어있지 않기 때문에 지금은 무시하기로 한다.
진행 과정은 다음과 같다.
(django-sample) C:\WhiteSeolpyo\django-sample>cd django_sample
(django-sample) C:\WhiteSeolpyo\django-sample\django_sample>python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
June 15, 2025 - 15:34:57
Django version 5.2.3, using settings 'config.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
WARNING: This is a development server. Do not use it in a production setting. Use a production WSGI or ASGI server instead.
For more information on production servers see: https://docs.djangoproject.com/en/5.2/howto/deployment/
접속해보기
기본 접속 주소는 "127.0.0.1:8000"이다.
웹브라우저를 열고 "127.0.0.1:8000" 또는 "localhost:8000"으로 접속하면 다음과 같은 페이지를 확인할 수 있다.
접속 주소 변경하는 방법
"Starting development server at http://127.0.0.1:8000/"라는 문구에서 확인되는 것처럼 기본 접속 주소는 "http://127.0.0.1:8000/"이다.
"python manage.py runserver {접속 주소}" 명령을 실행하면 원하는 주소로 접속할 수 있도록 할 수 있다.
개발 단계에서는 127.0.0.1 이외로는 접속이 불가능하기 때문에 포트번호(8000)만 변경해보자. 접속 포트를 8009 포트로 변경한다면 다음과 같이 실행된다.
(django-sample) C:\WhiteSeolpyo\django-sample\django_sample>python manage.py runserver 127.0.0.1:8009
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
June 15, 2025 - 15:34:57
Django version 5.2.3, using settings 'config.settings'
Starting development server at http://127.0.0.1:8009/
Quit the server with CTRL-BREAK.
WARNING: This is a development server. Do not use it in a production setting. Use a production WSGI or ASGI server instead.
For more information on production servers see: https://docs.djangoproject.com/en/5.2/howto/deployment/