Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

897
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda