博客五部曲之一 - 简单博客


1416 浏览 5 years, 11 months

30 社会化分享链接

版权声明: 转载请注明出处 http://www.codingsoho.com/
from urllib import quote_plus

def post_detail(request, slug=None):
    instance = get_object_or_404(Post, slug=slug)
    share_string = quote_plus(instance.content)
    context = {
        "title" : instance.title,
        "instance" : instance,
        "share_string":share_string
    }
    return render(request, "post_detail.html",context)   

以微博为例,它的分享脚本为

        <a href="[http://v.t.sina.com.cn/share/share.php](http://v.t.sina.com.cn/share/share.php)?title={{share_string}}%20&url={{ request.build_absolute_url }}" target="_blank">share on weibo</a>

点击链接,它就会跳转到微博分享页面。