我正在使用Raspberry Pi开展一个小型大学项目。基本上,该项目是提供一个html接口来控制连接到Pi的传感器。我写了一个非常简单的Python代码,附带了一个非常基本的HTML代码。一切都在这条路径/ var / www / NewTest中完成。但是每次我尝试访问它都会引发500内部错误。我试过简单的" Hello World"与我一起工作的例子并尝试以同样的方式做这个例子但是没有用。
led.py
from gpiozero import LED
from time import sleep
from flask import Flask, render_template
app = Flask(__name__)
ledr = LED(17)
ledg = LED(27)
ledb = LED(22)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/red/')
def red():
ledr.off()
ledg.off()
ledb.off()
ledr.on()
return ' '
@app.route('/green/')
def green():
ledr.off()
ledg.off()
ledb.off()
ledg.on()
return ' '
@app.route('/blue/')
def blue():
ledr.off()
ledg.off()
ledb.off()
ledb.on()
return ' '
if __name__ == '__main__':
app.run(debug=True)
led.conf
<virtualhost *:80>
ServerName 10.0.0.146
WSGIDaemonProcess led user=www-data group=www-data threads=5 home=/var/www/NewTest/
WSGIScriptAlias / /var/www/NewTest/led.wsgi
<directory /var/www/NewTest>
WSGIProcessGroup led
WSGIApplicationGroup %{GLOBAL}
WSGIScriptReloading On
Order deny,allow
Allow from all
</directory>
</virtualhost>
的index.html
<!doctype html>
<title>Test</title>
<meta charset=utf-8>
<a href="/red/">RED</a> <br/>
<a href="/green/">GREEN</a><br/>
<a href="/blue/">BLUE</a>
任何想法? 谢谢!
答案 0 :(得分:0)
问题出在led.conf中。用户需要是pi。
<virtualhost *:80>
ServerName 10.0.0.146
WSGIDaemonProcess led user=pi group=www-data threads=5 home=/var/www/NewTest/
WSGIScriptAlias / /var/www/NewTest/led.wsgi
<directory /var/www/NewTest>
WSGIProcessGroup led
WSGIApplicationGroup %{GLOBAL}
WSGIScriptReloading On
Order deny,allow
Allow from all
</directory>
</virtualhost>