无法将Flask导入Kivy iOS

时间:2016-05-30 10:10:58

标签: python ios ipad flask kivy

我想将ReactJS导入Kivy iOS项目并在iPad上创建服务器。

但是当我跑步时,我遇到了这个错误:

Traceback (most recent call last):                                             
       File "/Users/macuser/kivy-ios/servi-ios/YourApp/main.py", line 15, in <module>  
     ImportError: No module named flask                                                                            
    2016-05-25 15:25:03.213 servi[40042:547076] Application quit abnormally!              
    2016-05-25 15:25:03.220 servi[40042:547076] Leaving    

如果我在OS X shell上部署相同的代码(使用命令python main.py),一切正常,但在XCode(7.3)中则没有。

如何将Flask导入Kivy项目?我的Mac上有Flask(sudo -H pip install flask,如果有人需要的话)

我的代码(main.py):(最后一行,错误)

import kivy
from kivy.app import App
from kivy.network.urlrequest import UrlRequest
from kivy.uix.gridlayout import GridLayout
import urllib
import flask
from flask import Flask, Response, request

app = Flask(__name__, static_url_path='', static_folder='public')
app.add_url_rule('/', 'root', lambda: app.send_static_file('index.html'))


@app.route('/api/comments', methods=['GET', 'POST'])
def comments_handler():
    with open('comments.json', 'r') as f:
        comments = json.loads(f.read())

    if request.method == 'POST':
        new_comment = request.form.to_dict()
        new_comment['id'] = int(time.time() * 1000)
        comments.append(new_comment)

        with open('comments.json', 'w') as f:
            f.write(json.dumps(comments, indent=4, separators=(',', ': ')))

    return Response(
        json.dumps(comments),
        mimetype='application/json',
        headers={
            'Cache-Control': 'no-cache',
            'Access-Control-Allow-Origin': '*'
        }
    )


if __name__ == '__main__':
    app.run(port=int(os.environ.get("PORT", 3000)))

1 个答案:

答案 0 :(得分:0)

使用React Native可以编写Native Android / IOS应用程序。但是,您可以使用React Native,ReduxFlask Rest API在本地Android设备和远程服务器之间交换数据。