0

I will try to be as clear as possible since there are some things I do not fully understand how they work. I am developing a page in which an administrator can modify the image of one or any product that he wants, therefore I am storing the images in my dropbox developer account, there is no problem uploading the image on the page that is hosted with heroku but, I want to get the url of the image that the user uploaded and pass it to the html to specifically load that image hosted in dropbox.

Here is the method that I used from my model to get the url:

class TProducto(models.Model):
    id = models.AutoField( primary_key=True)
    Nombre = models.CharField(max_length=255, blank=True, null=True)
    Descripcion = models.CharField(max_length=255, blank=True, null=True)
    Costo = models.FloatField(default=0)
    Descuento = models.IntegerField(default=0)
    Coleccion = models.ForeignKey(TColeccione, on_delete=models.SET_NULL, blank=True, null=True)
    Foto_Producto = models.ImageField(upload_to="productos", blank=True, null=True);

    def get_img(self):
        return self.Foto_Producto.url

This is part of my settings:

# <=================== CONFIGURACION DE DROPBOX =============>
DEFAULT_FILE_STORAGE = 'storages.backends.dropbox.DropBoxStorage'
DROPBOX_OAUTH2_TOKEN = '<REDACTED>'
DROPBOX_ROOT_PATH = 'media'
# <=================== CONFIGURACION DE DROPBOX =============>

And in this part i want to get the url from dropbox to dynamically obtain the url of the image that the client uploaded to dropbox:

{% block content %}
    <section id="colecciones">
      <div class="container">
        <h2 class="subtitle">{{titulo}}</h2>

        {% for coleccion in colecciones %}
          <a href="/productos_coleccion/{{coleccion.id}}">
            <div class="row">
              <div class="col-sm-4">
                <div class="box-left">
                  <h2>{{coleccion.Nombre}}</h2>
                </div>
              </div>

              <div class="col-sm-8">
                <div class="box-img" style="background: linear-gradient(rgba(131, 131, 131, 0.3), rgba(131, 131, 131, 0.3)), url('{{coleccion.get_img}}');"></div>
              </div>
            </div>
          </a>
        {% endfor %}
      </div>
    </section>

It can be done with dropbox or I am trying to do something that can’t be done? Is it because I am trying to do this locally?

3

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.