網站超連結點擊情況儲存到mongodb

來源:互聯網
上載者:User

標籤:linux   python   django   

想看看有人點擊我首頁的新聞連結嗎 就自己寫了這個 看看,結果n天了 都是我自己點的 前端主要代碼(django模板)
<!-- HTML5 最新諮詢-->                <div class="djangonew" style="overflow:auto;float:right;aborder:1px solid red;height:10%;width:49%;">                <h4 style="color:#A52A2A2;background:#00CED1; text-align:center;">Html5最新動向</h4>                    {% for title,curl,date in h5news %}                    <p style="font-size:14px;color:black;border-bottom:1px solid #DCDCDC;margin:17px;"><a onclick="save_url(this)" href="{{curl}}" target="_blank">{{title}}</a>                    <span style="color:#A9A9A9;font-size:7px"> {{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")

查看:

650) this.width=650;" src="http://www.feifeiwd.com/static/img/blog/urlvisit.jpg" height="407" width="836" alt="urlvisit.jpg" />

本文出自 “半島學習筆記” 部落格,請務必保留此出處http://bandao.blog.51cto.com/4522715/1692318

網站超連結點擊情況儲存到mongodb

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.