Django, external link url amended to project url

494 views Asked by At

I have a Django project and want to take the user to an external link in openstreetmaps that is supplied lat and long from my Django model. In my view, I develop a url like this: "http://www.openstreetmap.org/?minlon=-92.024&minlat=57.5129102&maxlon=-91.52&maxlat=43.00&mlat=42.899&mlon=-91.774" and I provide it as a variable in my template. The link in my template is: <a id="map" target="_blank" href={{mapurl}}>map</a>. {{mapurl}} is the url fed from my view.

The problem is that Django tries to find a url conf that looks like: http://127.0.0.1:8000/beach/1825108/%22http://www.openstreetmap.org/?minlon=-92.0240039&minlat=42.78940921&maxlon=-91.5240039&maxlat=43.00940921&mlat=42.89940921&mlon=-91.7740039%22

rather than taking the user to the openstreetmap in a new page.

Any thoughts?

1

There are 1 answers

1
Jason On

You can write the URL directly in the template

eg

<a id='map'
   target='_blank'
   href='http://www.openstreetmap.org/?minlon={{minLon}}&minlat={{minLat}}&maxlon={{maxLon}}&maxLat={{maxLat}}&mlon={{mLon}}&mlat={{mLat}}'
>Map</a>

You'd just have to pass the various variables in the template context