如何在 Django 中将 @classmethod 作为 Celery 任务运行?这是示例代码:
class Notification(TimeStampedModel):
....
@classmethod
def send_sms(cls, message, phone, user_obj=None, test=False):
send_message(frm=settings.NEXMO_FROM_NUMBER, to=phone, text=message)
return cls.objects.create(
user=user_obj,
email="",
phone=phone,
text_plain=message,
notification_type=constants.NOTIFICATION_TYPE_SMS,
sent=True,
)
n = Notification()
n.send_sms(message='test', phone='1512351235')
Run Code Online (Sandbox Code Playgroud) 如何在看起来像这样的字符串中找到所有子字符串{{ test_variable }?
s = "hi {{ user }}, samle text, {{ test_variable } 2100210121, testing"
Run Code Online (Sandbox Code Playgroud)
我的尝试:
finds = re.findall(r"(\{{ .*?\}$)", s)
但是此正则表达式返回的子字符串也以}}而不是结尾,}所以我看到不需要{{ user }}的结果
我使用 Django 1.11 并收到此错误
class TenantMiddleware:
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
set_tenant_schema_for_request(request)
response = self.get_response(request)
return response
Run Code Online (Sandbox Code Playgroud)
我试图解决这个问题:
class TenantMiddleware:
def process_response(self, request, response):
set_tenant_schema_for_request(request)
return response
Run Code Online (Sandbox Code Playgroud)
这是使用“新”中间件风格的正确等价物吗?