Django signal receiving across apps -
i have main_app
, , app2
. main_app
list of items data, , app2
has more information said items.
main_app
isn't supposed know app2
, app2
can import main_app
.
within main_app/signals.py
, have
import django.dispatch mysignal = django.dispatch.signal(providing_args=['uid'])
in main_app/views.py
, have view renders various main_templates
, containing details of item, view editing, , 1 submitting said edited data. idea signal sent when each of called and, app2
receives this. main_template
uses "with
" call template2
, app's information.
in app2/processes.py
have following:
import django.dispatch django.dispatch import receiver import models main_app.signals import mysignal, (mysignal2, etc)
then each method, have
@receiver(mysignal) def foo(sender, **kwargs) etc
ok... so, in main_app/views.py
, if have line:
from app2.processes import mysignal, mysignal2 etc
everything works smoothly. want remove reliance on app2
in main_app
. far concerned, app2
importing these signals main_app/signals.py
. if try rid of above line , put following main_app/views.py
from main_app.processes import mysignal, my...
it doesn't work...i don't error data app2 doesn't render template, , don't see why....any ideas?
your signal receivers in app2 not registered. simple check: put raise exception("i imported!");
first line in app2/processes.py
. never see exception. have make sure signal receivers being registered. can import app2.processes
somewhere django look. example in app2/models.py
.
Comments
Post a Comment