ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I created with Vmware workstation an Ubuntu 20.04 server VM in which I also installed LAMP in order to run my little php/mysql projects. It works fine.
I started learning python as well, and I'd like now to develop little webapps which run in my browser (I flask too, I guess), the way I do with my php files.
Unfortunately, I haven't yet understood how to create a python server/environment to run my projects in my browser. I read plenty of articles about that, but each and every of them said somethign different, and, as a result, I am more confused than I was.
Could you help me figure it out please?
Thanks
I don't think you're asking about venv stuff - which I believe is for isolating dependencies of different applications (so still something you might want, but it wont solve the server aspect).
When I tried to figure this out, I first resorted to simply using Jetty FastCGI to connect to a Python script which manually printed HTTP responses - basically "import cgi,cgitb,os,sys" then parsing "os.getenv('PATH_INFO',''") and "os.getenv('QUERY_STRING','')" to figure out what to do, and finally sending the HTTP response with "sys.stdout.write"
It's not a great approach - in particular it means re-starting the application on every request - but it did allow me to just get started on the important code.
Later I came back and wrote a basic WSGI server for the app using wsgiref.simple_server.make_server, which runs the server+application continually until stopped.
I still need to return to that project at some point and figure out if that's an appropriate solution - I remember vague warnings about it only being for "evaluation purposes" or some similar nonsense, so need to confirm whether it's enough to put Jetty/Apache/nginx/etc in front of it, or whether I need yet another approach.
I don't think you're asking about venv stuff - which I believe is for isolating dependencies of different applications (so still something you might want, but it wont solve the server aspect).
When I tried to figure this out, I first resorted to simply using Jetty FastCGI to connect to a Python script which manually printed HTTP responses - basically "import cgi,cgitb,os,sys" then parsing "os.getenv('PATH_INFO',''") and "os.getenv('QUERY_STRING','')" to figure out what to do, and finally sending the HTTP response with "sys.stdout.write"
It's not a great approach - in particular it means re-starting the application on every request - but it did allow me to just get started on the important code.
Later I came back and wrote a basic WSGI server for the app using wsgiref.simple_server.make_server, which runs the server+application continually until stopped.
I still need to return to that project at some point and figure out if that's an appropriate solution - I remember vague warnings about it only being for "evaluation purposes" or some similar nonsense, so need to confirm whether it's enough to put Jetty/Apache/nginx/etc in front of it, or whether I need yet another approach.
I did what it says step by step and it works now, I mean, I have that "Hello world" message in my browser.
However, I am trying to figure out if there is a way to get it better than that since I got:
Code:
john@ubuntu-02:~/webapp$ python3 app.py
* Serving Flask app "app" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
when I ran python3 app.py in my linux shell.
Futhermore, am I supposed to run the same command everytime I reboot the server?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.