This is not a problem I thought I’d be running into any time soon, however, the nature of software development is such that unpredictable hurdles jump out at you at every stage of the development process.
The flask command is installed by Flask, not your application; it must be told where to find your application in order to use it. The FLASKAPP environment variable is used to specify how to load the application. Unix Bash (Linux, Mac, etc.): $ export FLASKAPP=hello $ flask run. App.run(debug=True) In line 1 you are making available the code you need to build web apps with flask. Flask is the framework here, while Flask is a Python class datatype. In other words, Flask is the prototype used to create instances of web application or web applications if you want to put it simple. Flask is a web development Framework for Python. It is fairly simple to get started. All you need to do is to pip install Flask into your virtualenv, give the FLASKAPP environment variable your file and run flask run (described in detail in installation and quick start). This will launch the development server and you can instantly start. Aug 28, 2018 How Does a Flask App Work? The code lets us run a basic web application that we can serve, as if it were a website. From flask import Flask app = Flask(name) @app.route('/') def home: return 'Hello, World!' If name 'main': app.run(debug=True) This piece of code is stored in our main.py.
I like to primarily describe myself as a web developer. The largest projects I’ve worked on in the past have all been web-based. There are several reasons for my preference in developing for the web. Firstly, the web is universal. Almost every device with a screen these days has a web browser built-in. Developing for the web allows me to reach as many devices and people as possible with my work. In addition to that, the web has a universal language, I can pick whatever stack I want and as long as I have some HTML, JS and CSS in the front-end, the browser will understand what I’m trying to say to it. The opposite is true for desktop applications (if you want to develop them natively, at least). As you’d need to work with different languages, frameworks, and codebases in order to develop for different systems. Desktop apps do have their advantages though. For one, if you are planning on building a stand-alone application, building a web app and deploying it to a server makes little sense, you’d be better off creating an app that can be packaged, installed, and run locally on a target machine.
The bootstrap flow. Run.py loads the.env file; Initialize the app using the specified profile: Debug or Production If env.DEBUG is set to True the SQLite storage is used; If env.DEBUG is set to False the specified DB driver is used (MySql, PostgreSQL).
This brings us to the topic of this article. Recently, I have been working on some personal software projects. Nothing I plan on sharing with the world as it’s software that I plan on using to improve my daily activities. However, even if the software was to be released, it has no real need to exist on the web, as it is fully functional when running locally. As I came to this realisation in the middle of development, I decided to change my approach from creating a web app to a desktop app. Being very far along the development process, it wasn’t very feasible to restart the entire project, so I set off looking for a way to convert my current app into a desktop app with the current codebase.
The project in question is built on flask, a python micro-framework for building small web-apps. You could build large apps with it but I would recommend a larger framework like Django for that purpose. Flask is very straight forward in the way it works. You can get set up with just a few lines of code as follows:
The code above creates a flask app server that displays “Hello, world!” on the browser when you visit localhost at the specified port(usually 5000 by default). Simple and fast, but, this is a web app. In order to access this, you’d have to start the server, open the browser and then load its address. In order to turn this into a desktop application, I incorporated the use of the flask-desktop library. This library allows us to convert a flask application to a desktop one with a few lines of code.
We have only added three lines of code here: importing the webui library, creating a ui object and passing it our app object, and finally replacing app.run with ui.run. That’s it! Really, that’s all there is to it. This app should be able to run on Mac, Windows, and Linux. You can even create a standalone executable using PyInstaller. The front-end of the application can still be developed using HTML templates, JavaScript and CSS.
Enjoyed the article or found it useful? Help out with a share and spread the word to other developers! Also feel free to drop a comment below. I’d love to hear your thoughts
I write awesome articles regularly. Subscribe so you don’t miss out on great content!
Hello Friends, In this article I will show you how to deploy a flask app on Heroku. Follow the below steps to deploy your python flask app on Heroku.
How To Run Flask App On Mac Computer
Prerequisite:
- You must have installed Git in your system.
- You must have installed Python in your system.
Step-1: Install Heroku CLI
Above command is for Mac, for other systems you can click here
Step-2: Create Python Virtual Environment
Step-3: Install Flask & Gunicorn
Step-4: Create an app folder and simple python app
main.py
Step-5: Create an entry point to the application, wsgi.py
wsgi.py
Step-6: Run the application in your local system
Step-7: Create requirements.txt and Procfile file
Procfile
Step-8: Create an app in Heroku
How To Run Flask Server
Step-9: Deploy your app to heroku
Step-10: Open your application on browser
Run Flask App On Ec2
It's done!
Run Flask App On Azure
Please Subscribe to my Youtube Channel https://youtube.com/c/codingx