想看看有人点击我主页的新闻链接吗 就自己写了这个 看看,结果n天了 都是我自己点的 前端主要代码(django模板)
<!-- HTML5 最新咨询--> <div class="djangonew" > <h5 >Html5最新动态</h5> {% for title,curl,date in h6news %} <p ><a onclick="save_url(this)" href="`curl`" target="_blank">`title`</a> <span > `date`</span> {% endfor %} </div> <script type="text/javascript"> $.ajaxSetup({ data: {csrfmiddlewaretoken: '{{ csrf_token }}' }, }); function save_url(t) { var data = { IP:"`IP`", url: t.href, }; $.post('/api/click_url', data); } </script>
后端代码(django)
#访问状态 @login_required(login_url="/") def Visit(request): r10=Redis(host='localhost',port=6379,db=10,password='**') r12=Redis(host='localhost',port=6379,db=12,password='**') #mongo Click_url today_sec = time.mktime(time.strptime(time.strftime("%Y%m%d"),"%Y%m%d")) curl_data = db.curl.find({'date':{'$gte':today_sec}},{'_id':0}) curl_data = list(curl_data) if len(curl_data): for i in curl_data: i['date'] = time.strftime("%Y%m%d %T",time.localtime(i['date'])) #在线 online_ipall=[] for i in r10.keys('IP*'): online_ipall.append((i,r10.get(i))) #今天 today_ipallwx=[] for i in r12.keys('IP*'): today_ipallwx.append((i,r12.lrange(i,start=0,end=-1))) today_ipall=sorted(today_ipallwx,key=lambda x:x[1][1],reverse=True) return render_to_response('plug/visit_state.html',{"curl_data":curl_data,"online_ipall":online_ipall,"today_ipall":today_ipall},RequestContext(request)) #点击超链接统计 def Click_url(request): if request.method == 'POST': url = request.POST.get('url') IP = request.POST.get('IP') db.curl.insert({'ip':IP, 'url':url, 'date':time.time()}) return HttpResponse("ok")
查看效果图:
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。