简体   繁体   English

如何在Sites框架Django框架中覆盖信号

[英]How to override a signal in the sites framework django framework

I have a model that is firing a post_save signal in the django framework set to run more than one site. 我有一个模型,该模型在django框架中触发post_save信号,该信号集可以运行多个站点。 What I need to do is to be able to override that signal with a signal that will be defined in the specific site that needs this signal and use the one in the main app as a base. 我需要做的是能够用将在需要此信号的特定站点中定义的信号覆盖该信号,并使用主应用程序中的信号作为基础。

Or maybe in short I want to be able to write these signals or any other code that is specific to each site in its own place but inheriting from the common code. 或者简而言之,也许我希望能够在自己的位置写这些信号或任何其他特定于每个站点但继承自通用代码的代码。

You should be able to do this by importing only the signals you need to use. 通过仅导入需要使用的信号,您应该能够做到这一点。 You could have a separate set of signal files for each of your sites, importing them relatively to your wsgi.py or manage.py files, which should allow you to override or extend your entire base signal library. 您可以为每个站点单独设置一组信号文件,将它们相对于wsgi.py或manage.py文件导入,这应该允许您覆盖或扩展整个基本信号库。

If all of your sites are running from one wsgi.py or manage.py file, you will probably have to test which files to import instead of relying on importing them relative to your cwd. 如果所有站点都从一个wsgi.py或manage.py文件运行,则可能必须测试要导入的文件,而不是依赖于相对于cwd导入文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM