последние элементы не появляются в flask - PullRequest
0 голосов
/ 08 апреля 2020

Я делаю flask приложение, и это на самом деле блог. И для базы данных я использую Firebase. Используя мои учетные данные администратора, когда я добавляю новости, последние новости не появляются. например, если я добавлю 3 новости, тогда третьи новости должны быть на вершине.

здесь находится файл html.

    {% block content %}
    <div class="row">
       <div class="col-lg-12 col-md-12 col-sm-12 col-12" style="margin-top: 25px; margin-bottom: 40px;">
  {% for trending_news in trending_news|reverse %}
   <div class="card " style="margin-bottom: 10px;">
    <div class="row">
      <div class="col-lg-8 col-md-8 col-sm-12 col-12">
        <div class="card-body">
          <div class="card-title" style="font-size: 1.3em;"><a href="/trending-news/{{ trending_news.title }}">{{ trending_news.title }}</a></div>
          <p class="small"><i>{{ trending_news.created_at }}</i></p>
          <p style="width:100%;height: 95px;overflow-y: hidden;scroll-behavior: smooth; text-align: justify; text-justify: inter-word;">{{ trending_news.description }}</p>
          <p><a href="/trending-news/{{ trending_news.title }}">Read full story</a></p>
        </div>
      </div>
      <div class="col-lg-4 col-md-4 col-sm-12 col-12">
        <div class="card-body">
          {% if trending_news.image != '' %}
          <img src="static/SERVER_FILES/img/{{ trending_news.image }}" class="img-responsive img-fluid z-depth-1 rounded" alt="1" style="width: 100%;height: 200px;">
          {% endif %}
        </div>

      </div>
    </div>
  </div>
  {% endfor %}
</div>
</div>
{% endblock %}

А вот файл py.

      @app.route('/add-trending-news', methods=['GET', 'POST'])
      @is_admin_logged_in
      def add_trending_news():
           if request.method == 'POST':
                created_at = datetime.now(timezone('Asia/Kolkata')).strftime("%B %d, %Y %I:%M:%S %p")
                title = request.form['title']
                description = request.form['description']
                source = request.form['source']
                image_name = ''

              if 'image' in request.files:
                  image = request.files['image']
                  img_ext = image.filename.rsplit('.', 1)[1].lower()
                  image.filename = 'img' + str(datetime.now().date()) + '_' + str(datetime.now().time()) + '.' + img_ext
                  image_name = secure_filename(image.filename)
                  image.save(os.path.join(app.config['SERVER_FILES_PATH'], image_name))
              else:
                 image_name = ''
                 tags = request.form['tags']
                 data = {
                             "created_at": str(created_at),
                               "title": str(title),
                             "description": str(description),
                           "source": str(source),
                           "image": str(image_name),
                          "tags": str(tags)
                         }
                  db.child(app.config['TABLE_NAME1']).push(data)

                 flash('New news added successfully. Want to add another news?' + Markup(
                       "<a href='/add-trending-news'> Click Here.</a>"), 'success')
                 return redirect(url_for('trending_news'))

            return render_template('add_trending_news.html')
...