0

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"
    print

I found on my search that

if args:
    print "response"
    print

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.

0

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 May 22 '15 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 May 23 '15 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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