• Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
HomepcDuinoPythonUse Flask to turn pcDuino into a Web Server
Previous Next

Use Flask to turn pcDuino into a Web Server

Posted by: admin , February 27, 2014

[vc_row][vc_column][vc_column_text]Flask is a Python web framework that can turn pcDuino into a dynamic web server.cool[/vc_column_text][vc_tour][vc_tab title=”Install libraries” tab_id=”1393488004-1-24″][vc_column_text]1. Install library Request (Request is one of the HTTP client libraries of Python)

$ sudo apt-get install python-requests

2.Install Python-pip (pip is a tool that can replace the easy_install and manage the  Python package) ;

$sudo apt-get install python-imaging python-imaging-tk python-pip python-dev git

Attention: Sometime it may fail to install when run with the above instruction,then you need to update the new source and run the commands again.

$sudo apt-get update

3.Install Flask( Flask is a low level of Web application framework ,written with Python)

$sudo pip install flask

[/vc_column_text][/vc_tab][vc_tab title=”Test code” tab_id=”1393488004-2-15″][vc_column_text]The filename of the following code will be saved as ‘hello-flask.py’:

from flask import Flask

app = Flask(__name__)

@app.route("/")

def hello():

          return " Welcome to pcDuino ! "

if __name__ == "__main__":

          app.run(host='0.0.0.0', port=80, debug=True)

[/vc_column_text][/vc_tab][vc_tab title=”Running test” tab_id=”1393545765163-2-6″][vc_column_text]1.1 Save the file as hello-flask.py and run

$sudo python ./hello-flask.py

QQ截图20130803014105

2.2  Input the instruction:

$ifconfig

to examine pcDuino IP address:

QQ截图20130803014105 (1)

3. On another PC computer which share the same subnetwork with pcDuino,  open the browser and input ’192.168.35’ (copy  the address obtained in the above step) you will see the following information:

图片3

4. At the same time, you will see the information as shown below  in pcDuino terminal.  It displays the client whose IP is 192.168.1.25 is connecting the pcDuino server:

图片4[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row]

Tags: Python

Share!
Tweet

admin

About the author

One Response to “Use Flask to turn pcDuino into a Web Server”

  1. Log in to Reply
    Jordan
    September 23, 2014 at 11:30 am

    I am still getting flask import error even though pip freeze shows flask as installed.

    Traceback (most recent call last):
    File “./flask.py”, line 1, in
    from flask import Flask
    File “/home/ubuntu/sportsinvesting/flask.py”, line 1, in
    from flask import Flask
    ImportError: cannot import name Flask

    pip Freeze gives me this:

    Warning: cannot find svn location for distribute==0.6.24dev-r0
    Flask==0.10.1
    Jinja2==2.7.3
    MarkupSafe==0.23
    PIL==1.1.7
    Werkzeug==0.9.6
    argparse==1.2.1
    ## FIXME: could not find svn URL in dependency_links for this package:
    distribute==0.6.24dev-r0
    itsdangerous==0.24
    pyxdg==0.19
    requests==0.8.2
    wsgiref==0.1.2

Leave a Reply Cancel reply

You must be logged in to post a comment.

Category

  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors