简体   繁体   English

使用Flask和Apache时出现内部错误500

[英]Internal Error 500 when using Flask and Apache

I am working on a small college project using Raspberry Pi. 我正在使用Raspberry Pi进行一个小型大学项目。 Basically, the project is to provide an html interface to control a sensor attached to the Pi. 基本上,该项目是提供一个html接口来控制连接到Pi的传感器。 I wrote a very simple Python code attached with a very basic html code also. 我写了一个非常简单的Python代码,并附带了一个非常基本的html代码。 Everything is done in this path /var/www/NewTest. 一切都在此路径/ var / www / NewTest中完成。 However everytime I try to access it throws a 500 internal error. 但是,每次我尝试访问它时,都会引发500个内部错误。 I tried simple "Hello World" examples that worked with me and tried to do this example the same way but didn't work. 我尝试了与我一起使用的简单“ Hello World”示例,并尝试以相同的方式进行此示例,但没有用。

led.py 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 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 的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>

any ideas? 有任何想法吗? Thanks! 谢谢!

The problem was in led.conf. 问题出在led.conf中。 The user needs to be pi. 用户需要是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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM