본문 바로가기
파이썬 웹 개발

[Django] SynchronousOnlyOperation: You cannot call this from an async context - use a thread or sync_to_async.

by 배추잠자리 2022. 11. 3.
반응형

SynchronousOnlyOperation: You cannot call this from an async context - use a thread or sync_to_async.

파이썬 장고 SynchronousOnlyOperation: You cannot call this from an async context - use a thread or sync_to_async.

비동기 함수 SynchronousOnlyOperation: You cannot call this from an async context - use a thread or sync_to_async.

[Django] SynchronousOnlyOperation: You cannot call this from an async context - use a thread or sync_to_async.

 

# 파이썬 장고(Django)에서 비동기 함수 내 orm을 사용했을 때 생기는 에러이다.

 

 

# 해결방안

settings.py 또는 프로젝트의 설정 부분에서

os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = 'true'

설정해서 해결할 수 있다.

 

또는 Celery를 활용하는 방향으로 개발할 수 있다.

 

 

 

# 파이썬 장고 비동기 함수(asyncio)

 

https://bcdragonfly.tistory.com/83

 

[Django] 파이썬 장고 비동기 함수_ asyncio 활용하기

[Django] 파이썬 장고 비동기 함수_ asyncio 활용하기 [Django] python django 비동기 함수_ asyncio 활용하기 SynchronousOnlyOperation: You cannot call this from an async context - use a thread or sync_to_async. 파이썬 장고에서 개

bcdragonfly.tistory.com

 

반응형

댓글