开启代码之旅 Launch With Code


1158 浏览 5 years, 6 months

14 Create a Social Sharing Page Part 2

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

分享页的增强显示,增加了count和ref_url

SHARE_URL = "[http://127.0.0.1](http://127.0.0.1):8000/?ref="

from django.shortcuts import render, HttpResponseRedirect, Http404
from django.conf import settings

def share(request, ref_id):
    try:
        join_obj = Join.objects.get(ref_id=ref_id)
        friends_referred = Join.objects.filter(friend=join_obj)
        count = join_obj.referral.all().count()
        ref_url = settings.SHARE_URL + str(join_obj.ref_id)
        context = {"ref_id": join_obj.ref_id, "count": count, "ref_url": ref_url}
        template = "share.html"
        return render(request, template, context)
    except:
        raise Http404