明显错误。行:1,列:1,Flask中的语法错误

2024-09-29 01:31:34 发布

您现在位置:Python中文网/ 问答频道 /正文

  • 我正在尝试将manifest.json文件链接到我创建的网站,以将其转换为PWA。已使用html/csspython flask作为后端
  • 我不知道这是路径问题还是其他问题。服务人员被检测到,工作绝对正常
  • 但在应用程序清单中,我得到的错误清单不是有效的JSON。行:1,列:1,意外标记 enter image description here
  • manifest.json文件

{
  "name": "Flask-PWA",
  "short_name": "Flask-PWA",
  "description": "A progressive webapp template built with Flask",
  "theme_color": "transparent",
  "background_color": "transparent",
  "display": "standalone",
  "orientation": "portrait",
  "scope": "/",
  "start_url": "../templates/login_user.html",
  "icons": [
    {
      "src": "images/icons/icon-72x72.png",
      "sizes": "72x72",
      "type": "image/png"
    },
    {
      "src": "images/icons/icon-96x96.png",
      "sizes": "96x96",
      "type": "image/png"
    },
    {
      "src": "images/icons/icon-128x128.png",
      "sizes": "128x128",
      "type": "image/png"
    },
    {
      "src": "images/icons/icon-144x144.png",
      "sizes": "144x144",
      "type": "image/png"
    },
    {
      "src": "images/icons/icon-152x152.png",
      "sizes": "152x152",
      "type": "image/png"
    },
    {
      "src": "images/icons/icon-192x192.png",
      "sizes": "192x192",
      "type": "image/png"
    },
    {
      "src": "images/icons/icon-384x384.png",
      "sizes": "384x384",
      "type": "image/png"
    },
    {
      "src": "images/icons/icon-512x512.png",
      "sizes": "512x512",
      "type": "image/png"
    }
  ]
}
  • 这是清单的文件结构

enter image description here


Tags: 文件nameimagesrcjsonflaskpnghtml
1条回答
网友
1楼 · 发布于 2024-09-29 01:31:34

更改内容类型

检查开发人员控制台中的网络选项卡,并查找manifest.json请求。如果响应的内容类型为text/html,那么您可能需要添加一个额外的头,将路由中的Content-Type更改为application/json

使用python对象

如果更改内容类型无效,则可以将整个清单作为python对象编写,然后jsonify将其返回到浏览器

from flask import jsonify
@app.route('/manifest.json')
def manifest():
    return jsonify(manifest_python_object)

相关问题 更多 >