Add a full_url property to image rendition objects
See original GitHub issueIs your proposal related to a problem?
To include a Twitter ‘share’ image on a template, you’d typically do something like:
{% image page.social_image fill-1200x1200 as social_img %}
<meta name="twitter:image" content="{{ social_img.url }}">
However, this may return either a local URL (/media/images/foo.jpg
) or an absolute URL (https://media.example.com/images/foo.jpg
) depending on how media files are configured at the Django level. There’s no good way to consistently return a full absolute URL, as required for the ‘share’ image to work.
Describe the solution you’d like
Add a full_url
property to the image Rendition model, which prepends settings.BASE_URL
to the rendition’s url
property if it begins with a /
, and returns the url unchanged if not. This will then allow us to write
<meta name="twitter:image" content="{{ social_img.full_url }}">
(Using settings.BASE_URL
isn’t perfect - it’s only an informal convention for Wagtail sites to define it, and it doesn’t account for multi-site installations - but it’s probably good enough for most purposes.)
Issue Analytics
- State:
- Created 3 years ago
- Reactions:7
- Comments:14 (6 by maintainers)
Top GitHub Comments
@kevinhowbrook has applied a fix for this on RCA: https://github.com/torchbox/rca-wagtail-2019/pull/551/files
Hey @sankalpmukim, are you still working in this issue? If not, I might want to work in this 😃