我是第一次尝试这个,我在导入信号时出错
来自 apps.py
from django.apps import AppConfig
class ChitchatConfig(AppConfig):
name = 'chitchat'
def ready(self):
import users.signals
来自 signals.py
from django.db.models.signals import post_save
from django.contrib.auth.models import User
from django.dispatch import receiver
from .models import user_Profile
@receiver(post_save,sender=User)
def create_profile(sender,instance,created,**kwargs):
if created:
user_Profile(user=instance)
@receiver(post_save,sender=User)
def save_profile(sender,instance,**kwargs):
instance.user_Profile.save()
白衣染霜花
相关分类