如何URL编码这样我可以把它传递给Facebook分享? [英] How to URL encode this so I can pass it to Facebook Share?
问题描述
这是我要分享的网址:
http://mydomain.com/#url=http:/ /stackoverflow.com
在我的网站内,我在Django中执行此操作,以使所有内容都可以正常工作: p>
http://mydomain.com/#url= {{external | urlencode}}
但是,当我将其传递给Facebook Share时,所有事情都被弄乱了。
http://www.facebook.com/sharer.php?u=<url共享>& t =<内容标题>
我试图urlen编码#url部分,还有完整的url,但它不工作,当$ &和
在各地的迹象。
我认为问题是,你首先urlencode最后一部分的URL,然后您将其包含在另一个URL中。
尝试使用 urllib
:
import urllib
urllib.quote(http://mydomain.com/#url=http://stackoverflow.com)
或者你必须取消引号:
urllib.unquote(http%3A // mydomain.com /%23url%3Dhttp%3A // stackoverflow.com)
/ pre>
亲切
This is the URL I want to share:
http://mydomain.com/#url=http://stackoverflow.com
Inside my site, I do this in Django so that everything will work:
http://mydomain.com/#url={{external|urlencode}}
However, when I pass it to Facebook Share, everything gets messed up.
http://www.facebook.com/sharer.php?u=<url to share>&t=<title of content>
I tried to urlencode the #url part, and also the full url, but it's not working, and my #url is not holding up when there are
& and ?
signs everywhere.解决方案I think the problem is, that you first urlencode the last part of url, which you then include into another url.
try use
urllib
for that:import urllib urllib.quote("http://mydomain.com/#url=http://stackoverflow.com")
or when you have to unquote something:
urllib.unquote("http%3A//mydomain.com/%23url%3Dhttp%3A//stackoverflow.com")
kind regards
这篇关于如何URL编码这样我可以把它传递给Facebook分享?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!