Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

896
Views
Flask at first run: Do not use the development server in a production environment

I installed the Flask plugin in PyCharm Community Edition and I just have this simple code in my flask app:

from flask import Flask
app = Flask(__name__)

@app.route('/')
def index():
    return '<h1>Hello!</h1>'

if __name__ == "__main__":
    app.run(debug=True)

And I get this message:

WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead

* Restarting with stat
* Debugger is active!
* Debugger PIN: 123-456-789
* Running on http://127.0.0.1:5000/

Why am I getting this error when I run Flask?


A previous version of the message read "Do not use the development server in a production environment."

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

For deploying an application to production, one option is to use Waitress, a production WSGI server.

Here is an example of using waitress in the code.

from flask import Flask

app = Flask(__name__)

@app.route("/")
def index():
    return "<h1>Hello!</h1>"

if __name__ == "__main__":
    from waitress import serve
    serve(app, host="0.0.0.0", port=8080)

Running the application:

$ python hello.py

Waitress also provides a command line utility waitress-serve. To use that, you can modify the code to the following:

from flask import Flask

app = Flask(__name__)

@app.route("/")
def index():
    return "<h1>Hello!</h1>"

def create_app():
   return app

Then we can use waitress-serve as the following:

waitress-serve --port=8080 --call hello:create_app

And BTW, 8080 is the default port.

To validate the deployment, open a separate window:

% curl localhost:8080
<h1>Hello!</h1>%                     

Or directly in your browser http://localhost:8080/.


Other alternatives to deploy your app include Gunicorn and uWSGI. For more details, please refer to the flask deploy doc.

over 4 years ago · Santiago Trujillo Report

0

Unless you tell the development server that it's running in development mode, it'll assume you're using it in production and warn you not to. The development server is not designed for production use. It is not designed to be particularly efficient, stable, or secure.

Enable development mode by setting the environment variable FLASK_ENV to development .

 $ export FLASK_APP=example $ export FLASK_ENV=development $ flask run

If you're running PyCharm (or probably any other IDE), you can set environment variables in the run configuration.

Development mode enables the debugger and reloader by default. If you don't want them, pass --no-debugger or --no-reloader to the run command.


However, that warning is just a warning, it's not an error that prevents your app from running. If your app doesn't work, there is something else wrong with your code.

over 4 years ago · Santiago Trujillo Report

0

If for some people (like me earlier) the above answers don't work, I think the following answer would work (for Mac users I think) Enter the following commands to do flask run

$ export FLASK_APP = hello.py
$ export FLASK_ENV = development
$ flask run

Alternatively you can do the following (I haven't tried this but one resource online talks about it)

$ export FLASK_APP = hello.py
$ python -m flask run

source: For more

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!