Python, postgres
Местоположение
Россия

Лучшие ответы пользователя

Все ответы (2)
  • Как реализовать возможность выбора столбцов для выгрузки с БД на сайт?

    @Atroshchenko-Dima Автор вопроса
    Python, postgres
    Нашел решение, может быть пригодится потом кому-нибудь.

    columns обрабатываем аналогично переменным year и station.
    sql запрос будет выглядеть так
    cur.execute("SELECT {} FROM fact_indicators WHERE fact_year = ANY(%s) AND fact_indicators = ANY(%s) AND fact_station_name = ANY(%s);".format(",".join(["\"{}\"".format(c) for c in columns])),(year, indicators, station))


    index.html

    <table class="table-fill">
      <thead>
        <tr>
          {% for column in columns %}
          <th>{{ column }}</th>
          {% endfor %}
        </tr>
      </thead>
    
    {% for row in rows %}
        <tr>
          {% for column in columns %}
          <td>{{ row[loop.index0] }}</td>
          {% endfor %}
        </tr>
    {% endfor %}
        </tbody>
      </table>
    </body>
    Ответ написан
    Комментировать

Лучшие вопросы пользователя

Все вопросы (32)