小编sha*_*red的帖子

在 FastAPI 中从根目录提供静态文件

我正在尝试让 FastAPI 与 Svelte 一起工作。我已经使用 Svelte 构建了静态文件,现在我尝试通过 FastAPI 提供它们。问题是构建的 Svelte 文件global.css从根目录引用,这意味着我无法将它们安装在子文件夹中。

相反,我必须将它们安装在 root 上:

app.mount("/", StaticFiles(directory="web/public", html=True), name="web")
Run Code Online (Sandbox Code Playgroud)

然而,这使得路由(函数装饰器)中定义的任何内容都无法访问。

是否可以同时定义静态文件函数?任何一个,

a) 路由优先,如果没有路由,它会尝试从静态目录中读取

b) 静态目录优先,我指定了一个排除路径,该路径改为路由

svelte fastapi

17
推荐指数
2
解决办法
7643
查看次数

Apache Beam Python SDK:如何访问元素的时间戳?

我正在通过ReadFromPubSubwith阅读消息timestamp_attribute=None,它应该将时间戳设置为发布时间。

这样,我最终得到 a PCollectionofPubsubMessage元素。

如何按顺序访问这些元素的时间戳,例如将它们保存到数据库?我能看到的唯一属性是dataand attributes,并且attributes只有来自 Pub/Sub 的键。

编辑:示例代码

with beam.Pipeline(options=pipeline_options) as p:
    items = (p
        | ReadFromPubSub(topic=args.read_topic, with_attributes=True)
        | beam.WindowInto(beam.window.FixedWindows(args.time_window))
        | 'FormatMessage' >> beam.Map(format_message)
        | 'WriteRaw' >> WriteToBigQuery(args.raw_table, args.dataset,
            args.project, write_disposition='WRITE_APPEND')
    )
Run Code Online (Sandbox Code Playgroud)

whereformat_message将使用 aPubsubMessage并返回一个字典,表示要附加到表中的行:

def format_message(message):
    formatted_message = {
        'data': base64.b64encode(message.data),
        'attributes': str(message.attributes)
    }
    return formatted_message
Run Code Online (Sandbox Code Playgroud)

python google-cloud-dataflow apache-beam

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