您好,登錄后才能下訂單哦!
想看看有人點擊我主頁的新聞鏈接嗎 就自己寫了這個 看看,結果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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。