J
J
Junior932018-12-21 20:20:26
Python
Junior93, 2018-12-21 20:20:26

How to pass connection parameters via command line?

python app.py oneparameter twoparameter threeparamenter

# app.py
from flask import Flask
app = Flask(name)

if name == 'main':
    parameters = get_parameters_from_cli()
    app.run(debug=True)

#views.py
@app.route("/")
def hello():
    # в некоторых views нужны параметры из командной строки которые я получил в фпйле app.py как их сюда передать?
    return "Hello World!"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2018-12-21
@Junior93

The argparse module will help parse the command line arguments . Save them in the context of the web application module flask.g .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question