I am new to python and I am trying to design a mobile app with a web server on a raspberry pi. I decided to write the server code using python because I want to control some pins and write on the database on the same server access, so I am wondering how can someone send a response using python CGI? And also if CGI is the best way to deal with python web servers? Or there are better ways to do that? And please if any one knows any link to a good python-server (request response) tutorial post it here.

I tried to return a response using this

#!/usr/bin/env python

import cgi

# print header
print "Content-type: text/html\n\n"

print "<h2>Arguments</h2>"

form = cgi.FieldStorage()
arg1 = form.getvalue('os')
print "OS: " +arg1+"<br>"

if args:
    print "response"

I found on my search that

if args:
    print "response"

will return a response "response" but when I tried it on fire bug nothing returned.

Also I found that return statement will give the response but it did not worked also.

1 Answer 1


I'd suggest Flask. It's a python "micro framework" tailored to do exactly what you're looking for. You can find python-flask in the raspbian repository.

  • For simple servers I like Bottle. It is very similar to Flask but has a single file dependency.
    – Craig
    Commented May 22, 2015 at 20:49
  • Bottle is definitely another contender. Both are in python, the RPi's "native" language, so easy to interface to other functions. I do like the framework bits of Flask, light as it is, but I don't have a lot of experience with either. I've just been pleased with how easy flask has been to get started. Lots of good documentation out there.
    – bobstro
    Commented May 23, 2015 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.