티스토리 뷰
GraphViz를 이용한 Django 모델 다이어그램 그리기
윈도우환경에서 GraphViz를 이용해 Django 프로젝트의 모델들의 다이어그램을 그려보겠습니다.
먼저 아래 링크로 들어가 GraphViz를 설치합니다.
https://graphviz.gitlab.io/_pages/Download/Download_windows.html
(msi, zip 아무파일이나 편한것을 선택하셔서 설치하시면 됩니다.)
설치후 설치파일 안에 있는 bin 폴더를 환경변수에 추가해줍니다.
ex) C:\Program Files (x86)\Graphviz2.38\bin
커맨드창을 열어 dot 명령이 잘 작동하는지 확인합니다.
파이썬과 GraphViz를 연결시켜줄 pygraphviz를 설치합니다. 또는 Dotplus를 설치하셔도 됩니다.
x$ pip install GraphViz
or
$ pip install Dotplus
하지만 설치도중 다음과같은 에러가 발생했습니다.
xxxxxxxxxx
.....
building 'pygraphviz._graphviz' extension
error: Microsoft Visual C++ 9.0 is required. Get it from http://aka.ms/vcpython27
같은 에러가 분은 https://www.lfd.uci.edu/~gohlke/pythonlibs/#PyGraphviz 에 접속하시면
.whl 파일을 다운받을 수 있습니다.
각자 환경에 맞는 .whl 파일을 받으시고 다음과 같이 설치합니다.
xxxxxxxxxx
$ pip install 파일명.whl
이제 django-extensions을 설치해야합니다.
xxxxxxxxxx
$ pip install django-extensions
잘 설치가 되었다면 django프로젝트 내의 settigns파일의 installed app에 추가해 줍시다.
xxxxxxxxxx
INSTALLED_APPS = (
...
'django_extensions',
...
)
이제 다음과 같이 테스트 해볼 수 있습니다.
xxxxxxxxxx
$ python manage.py graph_models -a -o test.png
'웹 개발' 카테고리의 다른 글
django의 lazy 함수 이해하기 (1) | 2019.01.22 |
---|---|
JWT(Json Web Token) (0) | 2018.07.03 |
댓글