Hello all.
I am trying to link a URL link with a marker for each location in folium. I have successfully reached this point, but I do not want the web page of that URL link to be show as an iframe.
The following is my map with markers:
When I click on “Paris” for instance, the following is what I am seeing:
The following is a section views.py file where the folium markers are being added to the map:
for i in range(0, len(data)):
folium.Marker(
location=[data.iloc[i]['latitude'], data.iloc[i]['longitude']],
popup=f"<a href=http://127.0.0.1:8000>{ data.iloc[i]['name'] }</a>",
).add_to(mapObject)
mapObject = mapObject._repr_html_()
content = {
'mapObject': mapObject,
'mapForm': mapForm,
}
return render(request, 'map_app/DisplayCities.html', content)
The following is the “DisplayCities.html” template which is what the DisplayCities view is rendering:
{% load crispy_forms_tags %}
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css"
integrity="sha384-zCbKRCUGaJDkqS1kPbPd7TveP5iyJE0EjAuZQTgFLD2ylzuqKfdKlfG/eSrtxUkn"
crossorigin="anonymous">
<title>Map Home Page</title>
</head>
<body>
<!--Navigation Bar-->
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Geographical World Map</a>
<button class="navbar-toggler" type="button" data-toggle="collapse"
data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="{% url 'display-map' %}">Global Map
<span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0" method="POST">
<!--The csrf_token is added for security.-->
{% csrf_token %}
{{ mapForm|crispy }}
<button class="btn btn-outline-success my-2 my-sm-0 mx-4" type="submit">Search</button>
</form>
</div>
</nav>
<div class="container">
<div class="row mt-4">
<div class="col-md-10 offset-md-1">
{{ mapObject|safe }}
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js"
integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/js/bootstrap.bundle.min.js"
integrity="sha384-fQybjgWLrvvRgtW6bFlB7jaZrFsaBXjsOMm/tB9LTS58ONXgqbR9W8oWht/amnpF"
crossorigin="anonymous"></script>
</body>
</html>
I would appreciate any advice on how I click on the title of each folium marker and have them redirect the user to a new web page without an iframe. Thank you.