有没有一种简单的方法将Flask服务器作为可执行文件分发? [英] Is there an easy way to distribute a Flask server as an executable?

查看:42
本文介绍了有没有一种简单的方法将Flask服务器作为可执行文件分发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Backbone.js构建一些简单的编辑器,并且希望能够将它们作为应用分发给用户,以便用户以客户端的方式编辑内容(即,我不希望用户必须设置MySQL或Apache之类的东西.

I'm building some simple editors with Backbone.js, and I'm hoping to be able to distribute them as apps for users to edit content in a mostly client-side way (i.e., I don't want users to have to futz with setting up stuff like MySQL or Apache).

所以我在想像这样的情况:

So I was imagining a scenario like:

  1. 用户下载.zip文件
  2. 在打开的结果文件夹中,用户单击index.html
  3. 在浏览器中打开
  4. 主干应用程序启动,将数据存储在 localStorage
  5. 然后用户可以导出到CSV.

信不信由你,这将解决我的问题:我想帮助用户在浏览器中编辑数据,然后以熟悉的格式将其取回(例如,可以将CSV加载到Excel中).

Believe it or not, that would solve my problem: I want to help users edit data in a browser and then get it back out in a familiar format (CSV can be loaded into Excel, for instance).

我想这样做而不强迫他们配置服务器.似乎在HTML5堆栈中这几乎是可能的.但是,在至少一个浏览器(Chrome)中,此方法不起作用,因为出现了这样的错误:

And I’d like to do this without forcing them to configure a server. It seems like this is almost possible in the HTML5 stack. However, in at least one browser (Chrome), this doesn't work, because I get errors like this one:

XMLHttpRequest cannot load file:///users/me/project/data/Appdata.json. Origin null is not allowed by Access-Control-Allow-Origin.

(奇怪的是,我在Firefox中没有收到该错误,并且 .js .json 文件可以正常加载.)

(Oddly enough, I don't get that error in Firefox, and the .js or .json files load fine.)

因此,在我看来,目前还没有办法让这些用户使用某种本地服务器来提供Backbone接口.

So at this point it seems to me that there's no way around having these users use something kind of local server to serve up the Backbone interface.

因此,我试图弄清楚如何构建可分发的跨平台可执行文件,该文件将允许我的用户启动Flask服务器.(我希望为Backbone.js应用构建一个REST后端.)

So, I'm trying to figure out how to build a distributable, cross-platform executable that will allow my users to start a Flask server. (I hope to build a REST backend to a Backbone.js app.)

这是一厢情愿的想法吗?我假设我可以让相关人员安装Python.

Is this wishful thinking? I'm assuming I can get the people in question to install Python.

这可行吗?似乎有很多方法可以打包Python程序((pyinstaller?py2exe?...).)因此,我想在这里问一下,以防有人知道我所考虑的堆栈解决方案.

Is this doable? There seem to be many ways to package up Python programs, (pyinstaller? py2exe? ...) So I thought I would ask here in case someone might know of a solution for the stack I have in mind.

TIA!

推荐答案

我的建议是围绕您的代码创建一个精简的服务包装.这将使服务器独立于您的主代码库运行-也允许用户直接关闭服务器(只需右键单击服务图标并选择退出").

My suggestion would be to create a thin service wrapper around your code. This will allow the server to run independently of your main codebase - also allowing the user to shut down the server directly (simply right clicking the service icon and selecting "Exit").

此答案应该可以帮助您入门.

This SO answer should help you get started.

阅读更新后的问题后,我认为猫鼬之类的东西可能更适合你的任务.这是一个可嵌入的Web服务器,它是FLOSS,具有python绑定.烧瓶可能是过大的杀伤力.

After reading your updated question, I think something like mongoose might be more suited to your task. It is an embeddable web server that is FLOSS and has python bindings. Flask might be overkill.

这篇关于有没有一种简单的方法将Flask服务器作为可执行文件分发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆