python - Getting an internal server error on flask web server -


i'm newbie raspberry pi , python coding. i'm working on school project. i've looked tutorials , examples maybe i'm missing something. want build web server based gpio controller. i'm using flask this. going this, i've started example. turning on , off led refreshing page.

so problem is, can't see response value on web server side. it's turning on , off led. want see situation online. couldn't. i'm getting , internal server error. i'm giving python , html codes. can me solving problem.

from flask import flask flask import render_template import rpi.gpio gpio  app=flask(__name__)  gpio.setmode(gpio.bcm)  gpio.setup(4, gpio.out) gpio.output(4,1) status=gpio.high  @app.route('/') def readpin():     global status     global response     try:         if status==gpio.low:             status=gpio.high             print('on')             response="pin high"         else:             status=gpio.low             print('off')             response="pin low"     except:         response="error reading pin"      gpio.output(4, status)      templatedata= {         'title' : 'status of pin' + status,         'response' : response         }      return render_template('pin.html', **templatedata)  if __name__=="__main__":     app.run('192.168.2.5') 

and line on html page.

<h1>{{response}}</h1>  

i think "response" doesn't value. what's wrong on this?

firstly helps run in debug mode:

app.run(debug=true)

this track down errors being suppressed.

next have @ line building title string:

'title' : 'status of pin' + status

if enable debug mode, should see saying int/bool can't converted str implicitly. (python doesn't know how add string , int/bool).

in order fix this, should explicitly cast status string:

'title' : 'status of pin' + str(status)

or better yet:

'title' : 'status of pin: {}'.format(status)


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -