Flask deployement on lighttpd and raspberry pi

2024/10/3 17:19:56

I'm trying to deploy a hello flask app to a raspberry pi using lighttpd fastCGI.

I followed the instructions on the http://flask.pocoo.org/docs/0.10/deploying/fastcgi/ to the best of my ability

Here is my flask app (/var/www/demoapp/hello.py)

from flask import Flask
app = Flask(__name__)@app.route("/")
def hello():return "Hello World From Flask Yeh!"if __name__ == "__main__":app.run(host='0.0.0.0', port=5000)

And here is my .fcgi file (/var/www/demoapp/hello.fcgi)

#!/usr/bin/python
from flup.server.fcgi import WSGIServer
from yourapplication import appif __name__ == '__main__':WSGIServer(app).run()

And here is what I added to my /etc/lighttpd/lighttpd.conf

fastcgi.server = ("/hello.fcgi" =>(("socket" => "/tmp/hello-fcgi.sock","bin-path" => "/var/www/demoapp/hello.fcgi","check-local" => "disable","max-procs" => 1))
)alias.url = ("/static/" => "/var/www/demoapp/static/",
)

I get a 404 Not Found error

By the way what is the /tmp/hello-fcgi.sock where do I get this file

Please help. I'm essentially trying to find a simple way to deploy flask on my raspberry pi web server. I have tried several methods. The fastcgi seemed to be the easiest. If there is an easier way then let me know please.

Thank you

Vincent

Answer

I believe the problem is that in your hello.fcgi file, you are importing a module named yourapplication, however, the flask application you created is named hello.

Try changing this line:

from yourapplication import app to from hello import app

Edit: Also - double check your url when testing - since your @app.route is set to the root, you must include the trailing slash in your url, eg:

http://xxx.xxx.x.xx/hello.fcgi/

and not

http://xxx.xxx.x.xx/hello.fcgi

https://en.xdnf.cn/q/70707.html

Related Q&A

Django admin asks for login after every click

Im working on a Django app hosted on Heroku. Im able to login to the admin with my username, password. But on every single click (or on each click after a few seconds) it redirects me to the login page…

Change numerical Data to Categorical Data - Pandas [duplicate]

This question already has answers here:How to create new values in a pandas dataframe column based on values from another column(2 answers)Closed 6 years ago.I have a pandas dataframe which has a numer…

Why is dataclasses.astuple returning a deepcopy of class attributes?

In the code below the astuple function is carrying out a deep copy of a class attribute of the dataclass. Why is it not producing the same result as the function my_tuple? import copy import dataclass…

customize dateutil.parser century inference logic

I am working on old text files with 2-digit years where the default century logic in dateutil.parser doesnt seem to work well. For example, the attack on Pearl Harbor was not on dparser.parse("12…

How can I check a Python unicode string to see that it *actually* is proper Unicode?

So I have this page:http://hub.iis.sinica.edu.tw/cytoHubba/Apparently its all kinds of messed up, as it gets decoded properly but when I try to save it in postgres I get:DatabaseError: invalid byte seq…

Test assertions for tuples with floats

I have a function that returns a tuple that, among others, contains a float value. Usually I use assertAlmostEquals to compare those, but this does not work with tuples. Also, the tuple contains other …

Django: Assigning ForeignKey - Unable to get repr for class

I ask this question here because, in my searches, this error has been generally related to queries rather than ForeignKey assignment.The error I am getting occurs in a method of a model. Here is the co…

Counting day-of-week-hour pairs between two dates

Consider the following list of day-of-week-hour pairs in 24H format:{Mon: [9,23],Thu: [12, 13, 14],Tue: [11, 12, 14],Wed: [11, 12, 13, 14]Fri: [13],Sat: [],Sun: [], }and two time points, e.g.:Start:dat…

Download A Single File Using Multiple Threads

Im trying to create a Download Manager for Linux that lets me download one single file using multiple threads. This is what Im trying to do : Divide the file to be downloaded into different parts by sp…

Merge string tensors in TensorFlow

I work with a lot of dtype="str" data. Ive been trying to build a simple graph as in https://www.tensorflow.org/versions/master/api_docs/python/train.html#SummaryWriter. For a simple operat…