django

8. Django admin

으누아빠 2020. 7. 13. 18:48
반응형

Django admin

  • 장고 서버 실행
  • python manage.py runserver
  • 서버를 실행하면 b.sqlite3 파일이 생성
  • 최종 데이터베이스는 아님 개발용
  • http://127.0.0.1:8000/에 접속을 하면 사이트에 접속이 되는것을 확인할 수 있음
  • Django 가 설치되면 관리자페이지가 자동으로 설치됨
PS D:\gongbang> python manage.py runserver 
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).

You have 17 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.

July 13, 2020 - 16:33:48
Django version 3.0.8, using settings 'config.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.

http://127.0.0.1:8000/admin 에 접속을 하면 테이블이 존재하지 않는다라는 오류메세지 발생

13개의 적용되지 않은 migragtion 있습니다. 해당 프로젝트는 app을 위한 migration들이 적용되지 않은한 작동하지 않을겁니다. 
적용하기 위해서는 'python manage.py migrate'를 실행하시기 바랍니다.

You have 13 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.

PS D:\gongbang> 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 sessions.0001_initial... OK
  • python manage.py migrate 변경사항을 데이터베이스에 적용

  • python manage.py makemigrations 변경사항에 대한 마이그레이션 생성

  • python manage.py migrate 을 실행하여 데이터 베이스를 적용해야함

관리자 계정생성

  • 보통 관리자 계정은 프로그램 단에서 작업을 하여 등록하나 Django 는 콘솔에서 등록
  • python manage.py createsuperuser
  • 생성된 admin 테이블에 관리자 계정을 생성
PS D:\gongbang> python manage.py createsuperuser
사용자 이름 (leave blank to use 'kangi'): manager
이메일 주소:
Password:
Password (again):
Superuser created successfully.
  • Django를 설치하면 자동으로 관리자페이지가 생성됨
  • 정상 접속이 됨