trying to get django / python to generate a urlencoded twitter web intent that shortens the url

53 Views Asked by At

I have a django template which is supposed to generate a twitter web intent share URL:

<a href="https://twitter.com/intent/tweet?text={{ block.value|urlencode }}%26url={{ page.get_site.root_url|urlencode }}{{ page.url|urlencode }}%26via=pathtweets

My understanding is that if everything is encoded properly, the URL should automatically be shortened to a t.co URL. Is that correct?

If so, what am I doing wrong?

In the template as shown, the final text renders to something like:

https://twitter.com/intent/tweet?text=Nostrud%20voluptate%20tempor%20eu%20elit%20laborum%20do%20excepteur%20commodo%20ipsum%20veniam%20velit%20minim.%20Proident%20irure%20velit%20enim%20tempor%20labore%20voluptate%20laboris%20esse%20excepteur%20nostrud%20et.%20Fugiat%20cillum%20magna%20reprehenderit%20qui%20irure%20sint%20in%20occaecat%20officia%20cillum%20proident%20elit%20ea%20pariatur.Nostr%26url=http%3A//localhost/en/my-article-2/%26via=pathtweets

in the URL, where the content of the tweet box renders as:

Nostrud voluptate tempor eu elit laborum do excepteur commodo ipsum veniam velit minim. Proident irure velit enim tempor labore voluptate laboris esse excepteur nostrud et. Fugiat cillum magna reprehenderit qui irure sint in occaecat officia cillum proident elit ea pariatur.Nostr&url=http://localhost/en/my-article-2/&via=pathtweets
1

There are 1 best solutions below

0
mheavers On BEST ANSWER

I figured it out - the dynamic url http://localhost was not registering to twitter as an actual url because there was no .com, .org, etc., so the 23 character URL count was not going into effect. Also realized that URL shortening doesn't actually happen in this step of the process, it just counts any URL over 23 characters as 23 characters toward your 280 limit.