'List is being split into characters when passed through url
I have a city_list I pass from the first view to the second view through the url. When I pass that list to the second view and iterate through it, it iterates through every character rather than the strings in the list. I'm not sure why this is and was wondering how to have the full list passed with the strings it contains.
first view template
<button id="price_button1" hx-post="{% url 'get_price' price_object.id user_city city_list 1 %}">Click</button>
first view
city_list = ["Montreal", "Milan", "Paris", "Singapore", "Barcelona", "Rome"]
second view
def get_price(request, id, user_city, city_list, number):
for city in city_list:
print(city)
output is
[
"
M
O
N
T
R
E
A
L
instead of Montreal
Solution 1:[1]
Views Parameters are strings, except when the type is defined in urls as int or something else.
I suggest that you convert the city to a json list (which is a string) in the first view and load that JSON string back to list in the 2nd view.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mohamed ElKalioby |
