0

I am trying to use Gdrive image url in django template

Django Template

<p>{{post.scr}}</p><li class="post"><a href="{{post.href}}"><img src="{{post.src}}" alt="{{post.alt}}" width=auto height="300px"><h4>{{post.name}}</h4></a></li>

Django Model

from django.db import models

class Post(models.Model):
    catname = models.CharField(max_length=15)
    href = models.CharField(max_length=100)
    scr = models.CharField(max_length=100)
    alt = models.CharField(max_length=100)
    name = models.CharField(max_length=100)

But actual url of scr is scr="https://drive.google.com/uc?id=xyz"

There is a error in loading in image from external source (gdrive img link)

<p>https://drive.google.com/uc?id=xyz</p>
<img src(unknown) alt="#img3" width="auto" height="300px">

How to pass a external img url as src url in Django

oneclick
  • 91
  • 2
  • 9

1 Answers1

0

Try This:

models.py

src = models.URLField(max_length=300 )

in template

<img src="{{post.src}}" alt="{{post.alt}}">

While adding object in src field:

https://drive.google.com/uc?id=IMAGE_ID