带有React客户端和RESTFULL API的烧瓶网络服务器
你好吗?
我正在尝试在同一烧瓶Web服务器上维护两个服务:一个React客户端(在“/中”可用)和RESTFULL API(可在“/api/”中使用)。
但是,所有路线均针对客户端,我无法将蓝图注册到“/api”。
@app.route('/', defaults={'path': ""})
@app.route('/<path:path>')
def client_route(path):
return 'Client'
app.register_blueprint(routes, url_prefix="/api")
""" Registro de rotas da aplicação """
我需要以“/api”开头来调用API路由,而所有其他所有其他路由路由(*)呼叫客户端react。
有人可以帮我吗?
How are you?
I'm trying to maintain two services on the same flask web server: A React client (available in "/") and a RestFull API (available in "/api/").
However, all routes are directed to the client and I cannot register the Blueprint to "/api".
@app.route('/', defaults={'path': ""})
@app.route('/<path:path>')
def client_route(path):
return 'Client'
app.register_blueprint(routes, url_prefix="/api")
""" Registro de rotas da aplicação """
I need routes starting with "/api" to call the API routes, while all other routes (*) call Client React.
Can anybody help me??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
main_view.py
app.py
设置蓝色打印时,输入' /api'而不是'prefix = /'节。哦,您已经这样设置了,但是就我而言,我在上面写了。
我希望这会有所帮助。
main_view.py
app.py
When setting the blue print, enter '/api' instead of 'prefix = /' section. oh You've already set it up like that, but in my case I write above .
I hope this helps.
您必须输入
api
不是\ api
。这是蓝图如何工作的链接: https://realpython.com/flaston.com/flask-blask-blask-bluask-bluask-bluask-bluask-blueprint/
You must enter
api
not\api
.Here is a link on how blueprints work: https://realpython.com/flask-blueprint/
我找到了解决方案!
您只需要交换寄存器的顺序,例如:
(*),您可以使用此React代码正确使用WebApp。
Thaks!
I found the solution!
You just need to swap the order of the register, like that:
(*) And you may use this React code to serve the webapp correctly.
Thaks!!