You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flask新增Shopify Blueprint路由出现404错误如何解决?

解决Flask Shopify Blueprint路由404问题

核心问题:请求路径不匹配

你的Shopify Blueprint设置了url_prefix='/shopify',所以路由/app_launched的完整访问路径应该是/shopify/app_launched,但错误日志显示你请求的是/app_launched,这直接导致404。

具体修复步骤

1. 修正请求路径

确保所有指向该路由的请求使用正确的完整路径:/shopify/app_launched。同时注意日志里的/app_launchedHTTP/1.1,这说明请求URL格式存在错误(路径与HTTP版本之间缺少空格),需要排查请求生成逻辑,保证URL构造规范。

2. 绑定Blueprint的before_request钩子

当前的before_request函数未绑定到shopify Blueprint,会被当作全局钩子执行,可能引发权限验证异常。需要修正装饰器:

@shopify.before_request
@login_required
@role_required('admin')
def before_request():
    """ Protect all of the admin endpoints. """
    pass

3. 确认Blueprint导入正确性

确保app.py中从正确路径导入shopify Blueprint,匹配你的目录结构:

from blueprints.shopify.views import shopify

4. 验证路由注册情况

可以在app启动后打印所有注册的路由,确认shopify的路由是否存在:

# 在create_app函数末尾添加
with app.test_request_context():
    print("所有注册的路由:")
    for rule in app.url_map.iter_rules():
        print(f"{rule.endpoint}: {rule.rule}")

运行后检查输出是否包含shopify.app_launched: /shopify/app_launched,如果没有,说明Blueprint未正确注册,需排查导入或注册逻辑。

内容的提问来源于stack exchange,提问作者Filipe Ferminiano

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 21:47:33