0

HELP pls. How to read images paths from a csv file in python?

I have the needed images in a img folder, which is located in the static dic. I have added the paths of these images in my csv file. How do I read those paths from the csv in the back-end/python and afterwards pass them to the html page? Currently I have boxes with the name, info and price of each pizza in every box, the pictures is the same in every box and I want to change that now. How do I do that? These are pieces of my code right now: CSV file is put togehter like this: name,ingredients,price,path images HTML: <div class="main"> {% if menuData != [] %} <div class="pizzas-order-container"> <div class="pizzas-container"> {% for productInfo in menuData %} <div class="pizza-box"> <form action="/menu/add-pizza" method="post"> <input value = "{{ productInfo['name'] }}" type="hidden" name="pizzaName"> <div class="pizza-image"> <img src="{{url_for('static', filename='img/pizza.png')}}" alt="Pizza Image"> </div> <h3 class="pizza-name">{{ productInfo["name"] }}</h3> <p class="pizza-ingredients">{{ productInfo["ingredients"] }}</p> <p class="pizza-price">{{ productInfo["price"] }}</p> <input class="add-button" type="submit" value="Add"> </form> </div> {% endfor %} </div> PY code: @app.route("/menu/add-pizza", methods = [POST_METHOD_NAME]) def menu_add_pizza(): newSelectedPizzaName = request.form["pizzaName"] return redirect(url_for("menu", selectedPizzas=newSelectedPizzaName)) @app.route("/menu", methods = [POST_METHOD_NAME, GET_METHOD_NAME]) def menu(): selectedPizzas = [] try: selectedPizzaName = request.args['selectedPizzas'] selectedPizza = {"name" : selectedPizzaName} selectedPizzas.append(selectedPizza) except: print("There are no selected pizzas!")

1st Nov 2022, 6:40 PM
c
c - avatar
1 Resposta
+ 2
https://www.sololearn.com/Course/Intermediate_Python/?ref=app At the end of the course, there is a section all about working from/with files.
1st Nov 2022, 8:18 PM
Ausgrindtube
Ausgrindtube - avatar