'Unable to import Flask to Kivy iOS
I want to import ReactJS to Kivy iOS project and create a server on iPad.
But when I'm running I had this error:
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
If I deploy the same code on OS X shell (using the command python main.py) everything is OK, but in XCode (7.3) it's not.
How can I import Flask to Kivy project? I have Flask on my Mac (sudo -H pip install flask, if someone needs)
My code (main.py): (last line, the error)
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)))
Solution 1:[1]
Using React Native allow you to write Native Android/ IOS applications. You can however use React Native, Redux and Flask Rest API to interchange data between your local android device and the remote server.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | afidegnum |
