Flask, доступ к расширениям, обьявленным create_app через Blueprint

Имеется примерно такой файл init.py:

def create_app():     app = flask.Flask(name)     avatar = flask_avatar.Avatars(app)     return app 

В произвольном блюпринте user необходимо обратиться к методу обьекта avatar, ранее объявленного в create_app() Каким способом это можно сделать?

Service worker / caching a whole API in a Flask app?

I’m building a small scale app based on the Flask micro framework. In it, I have a service worker that caches the basic shell of my app (HTML, CSS and JS). However, I have dynamic content that is updated when some event occurs (i.e. click on a button which sends a request to the API endpoint, the backend does a bit of filtering and then it sends the processed data back to the UI).

How can I approach the caching of this API and is that possible at all? One way I thought of was to cache request by request until, gradually, I cache all of the possible responses. However, I’m not sure if there is another solution to make my app more accessible when in offline mode.

How do I link my python code into HTML without using flask (it doesn’t work on my computer)?

I’m thinking of making a GitHub website with python, but I’m not sure how to link python code into HTML.

I’ve tried several tutorials and searched through 3 pages of google search results (you know I’m desperate once I’ve done that). Please help me!

How do I link my python code into HTML without using flask (it doesn’t work on my computer)?

I’m thinking of making a GitHub website with python, but I’m not sure how to link python code into HTML.

I’ve tried several tutorials and searched through 3 pages of google search results (you know I’m desperate once I’ve done that). Please help me!

Pesquisa no Banco de Dados com valor de SelectField flask

Criei um campo de pesquisa usando SelectField mas ele não mostra o resultado no templates. o que estou fazendo de errado

Meu form

class FiltroForm(FlaskForm):     filtro = SelectField('Escolha a cidade', choices=[('Aracaju (SBAR)', 'Aracaju (SBAR)'), ('Aracaju (SBAR)', 'Aracaju (SBAR)'), ('Belém (SBBE)', 'Belém (SBBE)')])     submit = SubmitField('Selecionar') 

Banco de dados

class Listadevoo(db.Model):     id = db.Column(db.Integer, primary_key=True)     voo = db.Column(db.String(120))     origem = db.Column(db.String(120))     destino = db.Column(db.String(120))     aeronave = db.Column(db.String(120))     partida = db.Column(db.String(120))     chegada = db.Column(db.String(120)) 

Minha rota

@app.route('/voo', methods=["GET", "POST"]) def voo():     form = FiltroForm()         post = Listadevoo.query.filter_by(origem=form.filtro.data).all()     if form.validate_on_submit():         return redirect(url_for('voo'))     return render_template('voo.html', form=form, post=post) 

Templates

<div class="container-fluid">         <h1>voo</h1>         <form method="post" action="">           {{ form.hidden_tag() }}                 <p>{{ form.filtro.label }} {{ form.filtro }} {{ form.submit }}</p>        <hr>        <table>         <tr>           <th>Voo</th>           <th>Origem</th>           <th>Destino</th>           <th>Aeronave</th>           <th>Partida</th>           <th>Chegada</th>                   </tr>         {% for post in post %}         <tr>           <td>{{ post.voo }}</td>           <td>{{ post.origem }}</td>           <td>{{ post.destino }}</td>           <td><font color="#e3068f">{{ post.aeronave }}</font></td>           <td>{{ post.partida }}</td>           <td>{{ post.chegada }}</td>         </tr>         {% endfor %}       </table>          </div> 

Uma observação se eu remover form.filtro.data e colocar uma string ele mostra o resultado. Mas gostaria de usar aa função SelectField

@app.route('/voo', methods=["GET", "POST"]) def voo():     form = FiltroForm()         post = Listadevoo.query.filter_by(origem='São Paulo (SBSP)').all()     if form.validate_on_submit():         return redirect(url_for('voo'))     return render_template('voo.html', form=form, post=post) 

inserir a descrição da imagem aqui

Long term viability: Django vs Flask [on hold]

I recently had a frustrating discussion at work where a non-technical person insisted we switch from Flask to Django in my project because “Django scales better,” meaning it’s easier to hire django developers, easier to get them started (because django has more rules), and easier to hire agencies to work on django.

I spent a lot of time feeling incredulous of all the points above, but I’m curious, are they true? How would a person even measure such things?

Python flask static status 304

Estou tendo um problema com o flask, ele esta me retornando um erro 304 para arquivos CSS.

<!DOCTYPE html> <html lang="pt-br"> <head>     <meta charset="UTF-8">     <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">      <!-- Bootstrap CSS -->     <!--<link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap/bootstrap-reboot.min.css') }}">-->     <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/bootstrap/bootstrap.min.css') }}">     <!--<link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap/bootstrap-grid.min.css') }}">-->     <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/bootstrap/dataTables.bootstrap4.min.css') }}">     <!-- Ga.IA -->     <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/gaia/main.css') }}">     <title>Ga.IA</title> </head> <body>      <div class="container">     {% block content %}     {% endblock %}     </div>  <footer class="footer">     <p class="navbar-brand">Versão: {{ sistema['versao'] }} - 2019 (c) - Bruno La Porta</p> </footer>      <!-- jQuery primeiro, depois Popper.js, depois Bootstrap JS -->     <script type="text/plain" src="{{ url_for('static', filename='js/jquery/jquery-3.4.1.min.js') }}"></script>     <script type="text/plain" src="{{ url_for('static', filename='js/jquery/jquery.mask.min.js') }}"></script>     <!--<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>-->     <script type="text/plain" src="{{ url_for('static', filename='js/bootstrap/bootstrap.min.js') }}"></script>     <!-- DataTable -->     <script type="text/plain" src="{{ url_for('static', filename='js/jquery/jquery.dataTables.min.js') }}"></script>     <script type="text/plain" src="{{ url_for('static', filename='js/bootstrap/dataTables.bootstrap4.min.js') }}"></script>     <!-- Sweet Alert -->     <script type="text/plain" src="{{ url_for('static', filename='js/sweet_alert/sweetalert.min.js') }}"></script>     <!-- Ga.IA -->     <script type="text/plain" src="{{ url_for('static', filename='js/gaia/main.js') }}"></script>     <script type="text/plain" src="{{ url_for('static', filename='js/gaia/usuario.js') }}"></script>     <script type="text/plain" src="{{ url_for('static', filename='js/gaia/cliente.js') }}"></script> </body> </html>  

O retorno no console é o seguinte:

127.0.0.1 – – [13/Jun/2019 22:55:07] “GET /destino/17 HTTP/1.1” 200 –
127.0.0.1 – – [13/Jun/2019 22:55:07] “GET /static/css/bootstrap/bootstrap.min.css HTTP/1.1” 304 –
127.0.0.1 – – [13/Jun/2019 22:55:07] “GET /static/css/bootstrap/dataTables.bootstrap4.min.css HTTP/1.1” 304 –
127.0.0.1 – – [13/Jun/2019 22:55:07] “GET /static/css/gaia/main.css HTTP/1.1” 304 –

Obs.: Os arquivos JS tem que ficar como type="text/plain", caso contrario retornam o mesmo problema, já tentei usar este type no css e até mesmo deixar sem nenhum, o erro é o mesmo.

Flask configuration in digital ocean

This question may be simple and silly but bare my innocence on this concept

I have a python script which gives certain JSON format as output, I need to host on flask in digital ocean server

I have created a sample python file

from flask import Flask import os app = Flask(__name__)  @app.route("/")  def hello():     return "Hello World!"  if __name__ == "__main__":     app.run(host=os.getenv('IP', '111.11.111.11') /* this is my digital ocean ip */,             port=int(os.getenv('PORT', 4444))) 

I read through lot of blogs an pages but I didnt understand the concept of host=os.getenv('IP', '0.0.0.0')

So now front end team wants to consume this output from the python file, which IP should i use inside the file whether 111.11.111.11 or 0.0.0.0 ?

And If i want access the output through the browser it says Site cant be reached, I am browsing it this way http://111.11.111.11:4444 Am I doing right?