Reputation: 849
I have a django application where I am showing details of hospitals located in different location. I am able to render all the details but unable to render the source of iframe location to the template.
Below is my field to get source of iframe location.
models.py
class mydetails(models.Model):
Name=models.CharField(max_length=100,blank=True)
City=models.CharField(max_length=100,blank=True)
Location=models.TextField(max_length=5000,blank=True) #getting source of iframe
And I am rendering the the value of location as below in my html. views.py
class my_detailpage(generic.DetailView):
model = mydetails
template_name = 'hospital_app/detail.html'
detail.html
<iframe class="g-maps" src="{{ mydetails.Location}}" frameborder="0" style="border:0;" allowfullscreen="" aria-hidden="false" tabindex="0"></iframe>
the content inside the iframe source looks some thing like https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3806.9740157153647!2d78.46347561744385!3d17.413034599999996!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x3bcb975afb4afadd%3A0xf89ea8407df6c84!2sPrasads%20Multiplex!5e0!3m2!1sen!2sin!4v1595574993123!5m2!1sen!2sin
I tried taking the Location value as URLField as well in my models but was of no help.
When I inspected my template, found that my source details were empty even after loading the tag.
Upvotes: 1
Views: 669
Reputation: 2192
I'm pretty sure that when using a DetailView
, your model instance is accessed as object
in the template:
<iframe src="{{ object.Location }}"></iframe>
You can change this by providing a context_object_name
as noted here in the docs.
Upvotes: 1