DevOps/Django

[Django] django-pydenticon - 디폴트 프로필

bestwish 2023. 1. 28. 20:11

https://django-pydenticon.readthedocs.io/en/0.2/installation.html

 

Installation — Django Pydenticon 0.2 documentation

Configuring your Django installation Once Django Pydenticon has been installed, you need to perform the following steps in order to make it available inside of your Django project: Edit your project’s settings configuration file (settings.py), and update

django-pydenticon.readthedocs.io

git에서 사용하는 디폴트 이미지처럼 사용할 수 있게 해주는 라이브러리이다.

하지만 업데이트가 안되고있어서, 수정하여 사용해야한다.

 

1. 설치

pip install django-pydenticon

 

2.  적용

# settings.py
INSTALLED_APPS = [
	...
    'django_pydenticon',
    ...
]

# <project>/urls.py
from django_pydenticon.views import image as pydenticon_image

urlpatterns = [
    ...
    path('identicon/image/<path:data>/', pydenticon_image, name='pydenticon_image'),
]

공식문서에 나온 urls.py를 사용하면 에러가 난다. 위와 같이 수정해야 에러가 안난다.

https://github.com/azaghal/django-pydenticon/blob/master/django_pydenticon/views.py

 

GitHub - azaghal/django-pydenticon: Django Pydenticon is a Django application that builds upon Pydenticon, a Python implementati

Django Pydenticon is a Django application that builds upon Pydenticon, a Python implementation for generating identicons. Django Pydenticon exposes the capabilities of Pydenticon via web interface....

github.com

git에 있는 urls.py 내용을 수정하여 views.py의 image 를 사용한다.

 

에러발생 및 해결

\venv\lib\site-packages\django_pydenticon\settings.py", line 52, in <s.py", line 52, in <module> if not isinstance(PYDENTICON_DIGEST, collections.Callable): AttributeError: module 'collections' has no attribute 'Callable'

위와 같은 에러가 발생하는데, 파이썬 3.10 이상일 때 발생한다.

파이썬 3.9까지는 collections.Callable로 지원이 되었지만, 3.10부터는 collections.abc.Callable로 바뀌었다

라이브러리가 설치된 settings.py로 가서 수정해주면 된다.

# venv/Lib/site-packages/django_pydenticon/settings.py


...
if not isinstance(PYDENTICON_DIGEST, collections.abc.Callable): # 수정
    raise ImproperlyConfigured("Setting PYDENTICON_DIGEST must be a callable digest (usually from hashlib module).")