zoukankan      html  css  js  c++  java
  • web.py

    #-*- coding:utf-8 -*-
    import web
    import json
    import requests
    #from web.contrib.template import render_jinja
    #render=render_jinja('templates',encoding='utf-8')用jinja2渲染 urls
    =( r'/index','Index', r'/search','Search' )
    #db=web.database(dbn='mysql',host='',user='',pw='',port=,db='',charset-'utf8')
    #db.query|insert|update|delete render
    =web.template.render('templates')#webpy自带的渲染 def geturl(name): #request=requests.post('http://music.163.com/api/search/get/?type=1&s=%s&limit=10'%name,headers={'appver':'2.0.2','referer':'http://music.163.com'}) try: result=requests.get('http://s.music.163.com/search/get/?type=1&s=%s&limit=10'%name,headers={'appver':'2.0.2','referer':'http://music.163.com'}) result=json.loads(result.content.decode('utf-8')) if result.get('result'): return result['result']['songs'][0]['album']['picUrl'],result['result']['songs'][0]['audio'] else: return 'static/12.jpg','static/lizhi.mp3' except Exception as e: print e class Index(object): def GET(self): return render.a() class Search(object): def GET(self): text=web.input().get('search',None) imgurl,mp3url=geturl(text) return render.music(imgurl,mp3url) if __name__=='__main__': #print geturl('love') web.application(urls,globals()).run()
    #music.html
    $def with(imgurl,mp3url,data)
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
    </head>
    <body>
        <div style='background-image:url($:imgurl);800px;height:600px;background-repeat:no-repeat'>
            <div style='300px;height:32px;margin:0 auto;line-height:600px'> 
                <!--audio controls>
                        <source src="$:mp3url">
                </audio-->
    !--$for a in data:
        <p> $:a.title </p>--!> <audio src="$:mp3url" controls="controls"> </audio> </div> </div> </body> </html>

      

  • 相关阅读:
    祝大家光棍节快乐!
    [Spring] Oracle TopLink O/R Mapping integrates Spring.
    VS2005 vs Eclipse, functions i expected.
    [English] Adverb for link (Chinese)
    有几个Gmail的Invitation
    Experience online service of MS small business (bCentral)
    多态(Polymorphism)
    Check your site and build meta tags for search engines
    关于怎样用javascript判断网页上我们想要必须选择的复选框至少选择一个的问题
    关于在VS2010中学习c++的MFC
  • 原文地址:https://www.cnblogs.com/howhy/p/7419297.html
Copyright © 2011-2022 走看看