장고 프로젝트 만들기 (1)

 

글. 수알치 오상문 

 

앞에서 예제 사이트 프로젝트를 위한 가상환경 mysite를 만들었습니다. 이 가상환경에서 장고 프로젝트를 만들겠습니다. 

 

장고 프로젝트 만들기 

 

mysite\Scripts 폴더에서 activate 명령을 실행하여 가상 환경을 활성화합니다.

 

이제 다음 명령으로 장고 프로젝트를 현재(여기서는 django_project\mysite\) 폴더에 만듭니다.

 

django-admin startproject config  . <엔터>    <-- 명령어 끝에 빈칸과 점이 있음에 주의!!!

 

그러면 mysite 폴더에 config 폴더와 manage.py 파일이 생겨납니다. 

 

데이터베이스 생성

다음 명령으로 mysite 예제 프로젝트에서 사용할 데이터베이스를 생성합니다.

 

python manage.py migrate  <엔터>

 

그러면 다음처럼 데이터베이스 관련 작업이 화면에 나타납니다.

(mysite) C:\django_project\mysite>python manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying admin.0003_logentry_add_action_flag_choices... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying auth.0008_alter_user_username_max_length... OK
  Applying auth.0009_alter_user_last_name_max_length... OK
  Applying auth.0010_alter_group_name_max_length... OK
  Applying auth.0011_update_proxy_permissions... OK
  Applying auth.0012_alter_user_first_name_max_length... OK
  Applying sessions.0001_initial... OK

 

이 작업이 끝나면 db.sqlite3 파일이 생겨난 것을 확인할 수 있습니다. 

 

장고 관리자 계정 만들기

 

(mysite) C:\django_project\mysite> python manage.py createsuperuser <엔터> 

 

Username (leave blank to use 'administrator'): admin
Email address: 이메일 계정 
Password: 사용할 패스워드
Password (again): 사용할 패스워드 다시 입력 
Superuser created successfully.

 

 

장고 웹서비스 사이트 확인하기 

 

python manage.py runserver 80 <엔터>

 

그러면 서버가 다음처럼 실행됩니다. 

Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
June 25, 2021 - 18:15:39
Django version 3.2.4, using settings 'config.settings'
Starting development server at http://127.0.0.1:80/
Quit the server with CTRL-BREAK.
[25/Jun/2021 18:15:50] "GET / HTTP/1.1" 200 10697
[25/Jun/2021 18:15:55] "GET /static/admin/css/fonts.css HTTP/1.1" 200 423
[25/Jun/2021 18:15:55] "GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1" 200 86184
[25/Jun/2021 18:15:55] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 200 85876
[25/Jun/2021 18:15:56] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 200 85692
Not Found: /favicon.ico
[25/Jun/2021 18:15:56] "GET /favicon.ico HTTP/1.1" 404 2105

 

이제 웹 브라우저를 실행하고 주소에 127.0.0.1을 입력하여 접속하면 다음처럼 장고 기본 웹 페이지가 동작하는 것을 볼 수 있습니다.

 

반응형

+ Recent posts