Site hyperlink Click to save to MongoDB

Source: Internet
Author: User
Tags curl

Want to see someone click on the news link on my page, I wrote this to see, the result n days is my own point of the front-end main code (Django template)
<!-- HTML5  Latest Consulting-->                 <div class= "Djangonew"  style= "overflow:auto;float:right;aborder:1px  solid red;height:10%;width:49%; " >                

Back-end Code (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")

View:

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

This article is from the "Peninsula Learning Notes" blog, so be sure to keep this source http://bandao.blog.51cto.com/4522715/1692318

Site hyperlink Click to save to MongoDB

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.