Hello stackoverflow community!
I have a question and I couldn't find any answers..
So I have a virtual Debain 20.04 Server and I'm accessing it using PuTTY to host my flask application (with uWSGI and nginx).
But it feels so confusing without an IDE.
So my question is: Are there any ways to run a Flask application using uWSGI and nginx in an IDE like Pycharm or vscode?
Deploy a flask application on Debain with uWSGI and nginx: https://www.vultr.com/docs/deploy-a-flask-website-on-nginx-with-uwsgi/
So my question is: Are there any ways to run a Flask application using uWSGI and nginx in an IDE like Pycharm or vscode?
You can run Flask application using multiple web servers, you do not need to use Nginx or uWSGI.
For a local development, it is recommend you run your application using a mini web server like Waitress that makes it is easy to run any WSGI protocol based application locally (no servers needed).
You are still likely to learn some terminal. Though in theory all actions can be done through an IDE, most of the tutorials assume that you need to know UNIX command line basics, because you are going to need to know those any case to be a productive as a Python developer. Figuring how to do it through an IDE will probably take more time than learning to use Pycharm's integrated terminal for the development.
Here is an example how I am working with a locally running Waitress server (w/code hot reload) when working in PyCharm IDE:
Related
I have written a Python Dash Application and it works completely fine on my local computer. Now, I want to be able to deploy this application on a server within the corporate network. I do NOT want to deploy this on Heroku etc because the datasource is an internal API. How do I go about deploying this application on the server? It's a Linux based machine.
I found this post that says use the code below but not quite sure where to add this piece of code.
waitress-serve --host=0.0.0.0 --port=8080 appname:app.server
The code you are referring to, waitress-serve, is a command-line wrapper bound to the function waitress.serve provided by Waitress.
You run it in your terminal or from a shell script.
Waitress is a production-quality pure-Python WSGI server with very acceptable performance. It has no dependencies except ones which live in the Python standard library. It runs on CPython on Unix and Windows under Python 3.7+.
You can install it with pip install waitress.
#see waitress-serve documentation here.
I know it might be a bad design but since we are developing the django website on our laptops which runs Win7, I thought it would be better to run django on a Windows platform only in production.
(Laptop is not powerful enough to run a Unix VM inside and our Unix team doesn't provide any Unix server with UI access (Only Putty) so using an IDE is impossible on Unix.)
I have deployed django with gunicorn and nginx on a Linux server very easily, but this time I have to deploy django on a Windows server with Apache on another Unix server (I know it sucks).
Our middleware team is asking(forcing) to run django components on a separate server so that they can manage their Apache (on Unix) instance comfortably. As far as I understand, Apache and django should reside on the same server for mod_wsgi to work.
Is this possible to keep Apache on a Unix machine and make a django website run from a Windows machine?
If not, what are the best possible solutions in my case? (Switch django on Unix? Use waitress on Django windows? Do not separate Apache and Django? etc.)
Regards,
Aditya
Try deploying on IIS instead, as it is the native Web Server on Windows Servers.
Checkout the django-windowsauth package, you can use it to deploy your project to IIS using few simple commands. https://github.com/danyi1212/django-windowsauth.
The best thing in my modest point of view is to create a unix docker image of your project
I am building a back end in python via the python flask application from IBM Cloud/Bluemix. I have heard/read a lot about people complaining regarding that Flasks built in server isn’t good for production. But how do I know if the application uses the Flask built in server or if IBM sets something else? Is there a simple way to see this in the code?
Deploying the Flask boilerplate app from the IBM cloud catalogue will indeed deploy a Flask application running on the Flask dev webserver.
You will need to alter the application if you want to run a production WSGI server.
I work for IBM and am in this stuff all day every day.
If you want to verify this, SSH into your application container on Cloud Foundry with the bash command
cf ssh <yourappnamehere>
You will need to have either the bluemix or cloud foundry CLIs installed and be logged in to the relevant endpoint before submitting this command.
It will open a bash shell in your application container, and you can cd around and open and/or download your project files for inspection.
This line:
app = Flask(__name__)
is a sure fire way to know that you are running a Flask web server application.
If you are concerned with which WSGI server your application is running under, checking your procfile (you should see this when SSHing int your container) will show you which command starts your application. If the command is
python <yourapp>.py
then you are running the dev server. Otherwise, you would be running some other python file, most likely via the server's command rather than the python command, that would import your application as a dependency.
You can also take a look at whether or not any WSGI server libraries were downloaded during the compilation of your droplet, and what command was used to start your application with
cf logs <yourappname> --recent
after deploying it.
Or, you can just believe me that the boilerplate deploys a Flask app under a Flask dev server.
A tutorial on running Flask on a different WSGI server:
https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-uwsgi-and-nginx-on-ubuntu-14-04
I have an application setup in Flask and running on localhost in a Windows environment. All of the tutorials I have read said to not use the default Flask server in production.
The production servers Gunicorn and uWSGI both only work in Unix. Is there a way to run either one of those through Windows?
Or do I need to switch the project over to a UNIX development environment?
There's many WSGI servers you can use to serve a Flask application. If you really need to deploy it to Windows, then I did find NWSGI, which might be worth a look.
I think it's fair to say that WSGI servers are few and far between on Windows, as this list only mentioned NWSGI. Unless you have a very good reason to deploy to Windows, I think you're probably better off opting for a *nix environment.
Even with this question answered I wanted to add that you can run wsgi apps on IIS
which is a production level web server.
the easiest example is how flask can run on azure (IIS) but I saw a link explaining it even better https://heejune.me/2015/04/22/running-python-flask-on-a-local-iis-not-azure-with-wfastcgi-py/
Waitress is a pure python solution for both Windows and Nix platforms that is no more complex to set up than the development server.
I built a small web app for a friend. That friend's computer will not be connected to the Internet when using the app, so deploying it on Heroku is not an option.
Is there a way to deploy it locally without having to install a complex web server? Something small that can be packaged with the application? Using the built-in Flask server seems to be discouraged when you go to "production", but for a local app is it ok?
If it's just going to be used offline by one person, then yes, the internal development server might be sufficient.
If you're looking for a simple way to send that app to her, then see pyinstaller:
pip install pyinstaller
pyinstaller your_app.py
Zip up the folder inside the new dist directory and pass that along.
If pyinstaller isn't for you, there are plenty of options.
If you're just running the app locally, it should be fine. The main issues with the dev server are security and performance, but for an app that's not exposed to the outside and that has a single user, it should work fine. Even though you're using the dev server, it's still a good idea to turn off debug mode and enable multiprocess mode.
from multiprocessing import cpu_count
app.run(debug=False, processes=cpu_count())
If you want a little more performance, consider using uwsgi or gunicorn. Both are good WSGI app servers that can be installed with pip along with your application.
gunicorn -w $(nproc) --threads 2 --max-requests 10 myproject:app