Because the request object contains references to things which aren't practical to serialize — like uploaded files, or the socket associated with the request — there's no general purpose way to serialize it.
Instead, you should just pull out and pass the portions of it that you need. For example, something like:
import tempfile
@app.task
def location(user_id, uploaded_file_path):
# … do stuff …
def tag_location(request):
with tempfile.NamedTemporaryFile(delete=False) as f:
for chunk in request.FILES["some_file"].chunks():
f.write(chunk)
tasks.location.delay(request.user.id, f.name)
return JsonResponse({'response': 1})
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…