0Pricing
Django Academy · 강의

리시버를 올바르게 연결하기

문제를 피하도록 apps.py에 시그널을 등록합니다

리시버를 올바르게 연결하기은(는) CoddyKit의 무료 Django Academy 강의입니다. 이것은 4개 중 2번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Django Academy 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Django Academy 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

Receivers Must Be Imported

A receiver only listens if Django actually imports the module it lives in. If the file is never loaded, the signal silently does nothing.

The Classic Trap

Putting receivers in models.py sometimes works by luck, and sometimes not. That fragility is the connection problem you want to avoid.

Use a signals.py File

The clean pattern is a dedicated signals.py inside your app that holds every receiver for that app in one obvious place.

from django.db.models.signals import post_save
from django.dispatch import receiver

@receiver(post_save, sender=Profile)
def sync(sender, instance, **kwargs):
    pass

The AppConfig.ready Hook

Django calls ready() on each app config once at startup. That is the official place to load your signal handlers.

Import Inside ready

In apps.py, import your signals module from inside ready so receivers register exactly once when the app boots.

from django.apps import AppConfig

class BlogConfig(AppConfig):
    name = "blog"

    def ready(self):
        from . import signals

Point default_app_config

Make sure your app uses that config. Modern Django auto-discovers apps.py, so a matching AppConfig class is usually enough.

connect Without a Decorator

Instead of @receiver, you can wire a handler with connect. It does the same job and is handy for dynamic registration.

post_save.connect(sync, sender=Profile)

Avoiding Double Firing

If a module is imported twice, a receiver can run twice. Centralizing registration in ready() keeps each handler connected only once.

The dispatch_uid Safety Net

Pass a unique dispatch_uid so Django refuses to connect the same receiver more than once, even across reimports.

post_save.connect(sync, sender=Profile, dispatch_uid="profile_sync")

Disconnecting Receivers

You can also call disconnect to stop a handler, which is useful inside tests that should not trigger side effects.

Keep One App's Signals Together

Grouping each app's handlers in its own signals.py keeps reactions discoverable and stops them from scattering across the codebase.

Quick Check

Recall where signal handlers should be registered.

Recap: Wiring Signals Right

You learned to keep receivers in a signals.py, import them from AppConfig.ready(), and use dispatch_uid to prevent duplicate connections. ✅

자주 묻는 질문

“리시버를 올바르게 연결하기” 강의는 무료인가요?

네 — “리시버를 올바르게 연결하기” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Django Academy 강의 전체를 잠금 해제할 수 있습니다. Django Academy 강의에는 총 4개의 강의가 포함되어 있습니다.

“리시버를 올바르게 연결하기”에서 뭘 배우나요?

문제를 피하도록 apps.py에 시그널을 등록합니다 브라우저에서 직접 실행하는 실습 코드로 Django Academy을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Django Academy을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Django Academy은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 2번째 강의입니다.

“리시버를 올바르게 연결하기” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Django Academy 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Django Academy 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. post_save와 pre_delete 시그널
  2. 리시버를 올바르게 연결하기
  3. 맞춤 미들웨어 작성
  4. 미들웨어 순서와 process_view
← Django Academy(으)로 돌아가기