小编dev*_*fan的帖子

如何在 Django 中将 @classmethod 作为 Celery 任务运行?

如何在 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)

python django celery

4
推荐指数
1
解决办法
1647
查看次数

如何在以{{开头并以}结尾的字符串中查找所有子字符串

如何在看起来像这样的字符串中找到所有子字符串{{ test_variable }

s = "hi {{ user }}, samle text, {{ test_variable } 2100210121, testing"
Run Code Online (Sandbox Code Playgroud)

我的尝试:

finds = re.findall(r"(\{{ .*?\}$)", s)

但是此正则表达式返回的子字符串也以}}而不是结尾,}所以我看到不需要{{ user }}的结果

python

2
推荐指数
1
解决办法
56
查看次数

__init__() 缺少 1 个必需的位置参数:'get_response'

我使用 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)

这是使用“新”中间件风格的正确等价物吗?

django

2
推荐指数
1
解决办法
881
查看次数

标签 统计

django ×2

python ×2

celery ×1