Michael Smith
Michael Smith

Reputation: 3447

How do I get my pinterest share button to render my custom image in Django?

I have code for sharing on pinterest in my site. The issue is that I can't get it to load a custom image.

Right now I have this where image_to_share is the path of the file:

<a href="https://www.pinterest.com/pin/create/button/
        ?url=http%3A%2F%2Fwww.flickr.com%2Fphotos%2Fkentbrew%2F6851755809%2F
        &media= {% static image_to_share %}
        &description={{photo.description}}"
        data-pin-do="buttonPin"
        data-pin-config="above">
        <img src="//assets.pinterest.com/images/pidgets/pin_it_button.png" />
</a>

When I inspect element in chrome I get the path for the image as :

<img src="http:// /static/assets/uploaded_files/1421974839_3_art2.jpg ">

However, it should look like this:

<img src="/static/assets/uploaded_files/1421974839_3_art2.jpg">

How do I remove the "http://" and the trailing white space so that my image gets rendered properly?

Upvotes: 0

Views: 388

Answers (1)

bakkal
bakkal

Reputation: 55448

You can simply add your site's domain either hardcoded or with Django site

&media={{your_site_domain}}{% static image_to_share %}

your_site_domain can be example.com e.g.

More on Django sites: https://docs.djangoproject.com/en/1.7/ref/contrib/sites/#django.contrib.sites.models.Site.domain

Upvotes: 1

Related Questions