我正在尝试在Django Celery任务中使用以下代码。
我收到了以下错误提示:
我试图实现的是将活跃用户从视图传递到django-aync-messages。欢迎提出任何建议或指出我的错误(包括更好的方法!)。
@app.task
def search(q, userstring):
uid = User.objects.get(username=userstring)
messages.info(uid, 'Initiating search in background.')
[...]
我的想法是这样调用它:
search.delay(self.request.user.get_username(), form.instance.query)
我收到了以下错误提示:
>[2014-06-05 12:04:04,352: ERROR/MainProcess] Task listthings.tasks.search[5aaa77b4-c7be-4d6a-9127-626e63d0dfbe] raised unexpected: DoesNotExist('User matching query does not >exist.',)
Traceback (most recent call last):
File "/webapps/wcw/local/lib/python2.7/site-packages/celery/app/trace.py", line 240, in trace_task
R = retval = fun(*args, **kwargs)
File "/webapps/wcw/local/lib/python2.7/site-packages/celery/app/trace.py", line 437, in __protected_call__
return self.run(*args, **kwargs)
__File "/webapps/wcw/webcamwatch/listcams/tasks.py", line 44, in search
uid = User.objects.get(username=userstring)__
File "/webapps/wcw/local/lib/python2.7/site-packages/django/db/models/manager.py", line 151, in get
return self.get_queryset().get(*args, **kwargs)
File "/webapps/wcw/local/lib/python2.7/site-packages/django/db/models/query.py", line 310, in get
self.model._meta.object_name)
Exception: User matching query does not exist.
我试图实现的是将活跃用户从视图传递到django-aync-messages。欢迎提出任何建议或指出我的错误(包括更好的方法!)。