Django Extensions로 django 슈퍼 파워 잠금 해제
7521 단어 django
설치
현재
django-extension
는 3.2.1
버전입니다. 다음 명령으로 설치하십시오.pip3 install django-extensions
구성
django_extensions
패키지를 INSTALLED_APPS
파일의 settings.py
섹션에 추가합니다.INSTALLED_APPS = (
...
'django_extensions',
)
이렇게 하면 앱이 시작될 때
django-extensions
가 로드됩니다.특징
이제 기능을 자세히 살펴 보겠습니다.
이 확장은 다양한 관리/쉘 명령으로 구성됩니다.
1. 쉘 플러스
django shell의 향상된 버전입니다. 모든 모델을 셸에 자동으로 로드합니다.
다음 명령을 사용하여 shell_plus를 실행할 수 있습니다.
./manage.py shell_plus
ipython, bpython, ptpython 또는 일반 셸을 사용하도록 Shell plus를 구성할 수 있습니다.
settings.py
에 다음을 추가합니다.# Always use IPython for shell_plus
SHELL_PLUS = "ipython"
예시 스크린샷:
여기에서 shell_plus에 대해 자세히 읽어보십시오.
2. 스쿼시 마이그레이션 삭제
스쿼시 마이그레이션은 여러 마이그레이션을 하나로 병합하는 방법입니다.
아래 명령은
blog
에서 0001
까지 0008
앱의 마이그레이션을 스쿼시합니다../manage.py squashmigrations blog 0001 0008
그러면 스쿼시된 새 마이그레이션이 생성됩니다. 다음은 파일 구조가 현재 어떻게 보이는지 보여줍니다.
├── 0001_initial.py
├── 0001_initial_squashed_0008_blogcomment_parent.py
├── 0002_blog_markdown_body.py
├── 0003_alter_blog_markdown_body.py
├── 0004_blog_views.py
├── 0005_blog_table_of_content.py
├── 0006_remove_blog_body_remove_blog_table_of_content.py
├── 0007_bloglikes_blogcomment.py
├── 0008_blogcomment_parent.py
그런 다음 다음 명령은 필요하지 않은 마이그레이션을 정리합니다.
# Delete leftover migrations from the first squashed migration found in blog
./manage.py delete_squashed_migrations blog
그 후 파일 구조에는 다른 마이그레이션을 삭제하는 찌그러진 파일만 포함됩니다.
0001_initial_squashed_0008_blogcomment_parent.py
3. 이메일 내보내기
다음 명령은 등록된 사용자 이메일을 파일로 내보냅니다.
./manage.py export_emails > emails.txt
emails.txt
파일은 아래와 비슷한 것으로 구성됩니다."admin" <[email protected]>;
"[email protected]" <[email protected]>;
"[email protected]" <[email protected]>;
"[email protected]" <[email protected]>;
"[email protected]" <[email protected]>;
"[email protected]" <[email protected]>;
"[email protected]" <[email protected]>;
"[email protected]" <[email protected]>;
"[email protected]" <[email protected]>;
"[email protected]" <[email protected]>;
"[email protected]" <[email protected]>;
"[email protected]" <[email protected]>;
"[email protected]" <[email protected]>;
"[email protected]" <[email protected]>;
"[email protected]" <[email protected]>;
"[email protected]" <[email protected]>;
"[email protected]" <[email protected]>;
"[email protected]" <[email protected]>;
"[email protected]" <test@gmail.com>;
"[email protected]" <[email protected]>;
"[email protected]" <[email protected]>;
"[email protected]" <[email protected]>;
"Umesh" <[email protected]>;
4. 비밀번호 생성
다음 명령은 제공된 길이에 대해 임의의 암호를 생성합니다.
./manage.py generate_password --length=8
Django core의 기본 암호 생성기를 사용합니다.
5. 그래프 모델
django-extensions가 설치되면 graph_models 명령을 사용하여 데이터베이스 스키마 및 관계의 이미지를 생성할 수 있습니다.
./manage.py graph_models -a -o models.png
그래프를 생성하려면
pygraphviz
또는 pydotplus
패키지가 필요합니다.pip3 install pygraphviz
또한 시스템에 다음 패키지를 설치해야 합니다.
apt-get -y install graphviz graphviz-dev #on debian system
다음과 같은 png 파일이 생성됩니다.
자세한 내용은 here에서 확인하세요.
6. 데이터베이스 재설정
다음 명령이 실행되어
DROP DATABASE
CREATE DATABASE
데이터베이스가 재설정됩니다../manage.py reset_db --noinput
7. 관리자 생성기
다음 명령은 콘솔에서 관리자 코드를 생성합니다. 그런 다음
admin.py
파일에서 사용할 수 있습니다.python manage.py admin_generator blog
그건 포장이야
또한
django-extensions
가 제공하는 것이 더 있습니다. 여기를 통해서 갈 수 있는 공식documentation입니다.행복한 학습!
Reference
이 문제에 관하여(Django Extensions로 django 슈퍼 파워 잠금 해제), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/umschaudhary/unlock-django-super-powers-with-django-extensions-4cid텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)