Solution 1 :

iget the error /(ㄒoㄒ)/~~

NameError: name 'values' is not defined

fix like the app.run()
from flask import Flask,render_template

app = Flask(__name__)


@app.route('/', methods=['GET'])
def page_show():
    values = [1, 2, 3, 4, 5]
    print(values)
    return render_template('default.html', values=values)

app.run()



<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <input
      type="text"
      id="values"
      list="val"
      multiple="multiple"
      class="searchTerm"
      name="value"
      placeholder="Type your values"
    />
    <select list="values" name="values">
      {% for val in values %}
      <option value="{{val}}" selected>{{val}}</option>
      {% endfor %}
    </select>
    <button type="submit" class="searchButton" name="form">
      <i class="fa fa-search"></i>
    </button>
  </body>
</html>

it works!

Solution 2 :

( ̄▽ ̄)”

import csv
from flask import Flask,render_template

app = Flask(__name__)
with open(r'demotemplatesTesting.csv') as f:
        reader = csv.reader(f)
        values = next(reader)
        values = values[:len(values)-1]

@app.route('/', methods=['GET'])
def page_show():
    values = [1, 2, 3, 4, 5]
    print(values)
    return render_template('default.html', values=values)

app.run()

Problem :

What do I have to do to add my selected values from python list to input without any js library?
I need to add them separately by comma. The problem is that I can selected one value, and can`t do it second time, so I have the loop to do it, but it does not work.

app.py:

import csv
from flask import Flask, jsonify, make_response, render_template, request,

with open('templates/Testing.csv') as f:
        reader = csv.reader(f)
        values = next(reader)
        values = values[:len(values)-1]

@app.route('/', methods=['GET'])
def page_show():
    return render_template('includes/default.html', values=values)

if __name__ == '__main__':
    app.run()

default.html:

    <input type="text" id="values" list="val" multiple="multiple" class="searchTerm" name="value" placeholder="Type your values">
    <select list="values" name="values">
    {% for val in values %}
      <option value="{{val}}" SELECTED>{{val}}</option>
    {% endfor %}
  </select>
    <button type="submit" class="searchButton" name=form>
      <i class="fa fa-search"></i>
    </button>

How to solve it? Thanks.

Comments

Comment posted by timur

it doesn`t work. Please see my updated code to get rid of errors.

Comment posted by wangjin

it works … import csv from flask import Flask,render_template app = Flask(

Comment posted by timur

in your code you can select value, but can`t select another again. and I need select another too and add it to the same input from which I can select values/

Comment posted by link

you can check this

By