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);width:800px;height:600px;background-repeat:no-repeat'>
<div style='width: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>
web.py的更多相关文章
- web.py框架入门
在使用微信搭建公众平台的时候,使用的是web.py这个方便简单的框架,学习一下. 框架文档:http://webpy.org/docs/0.3/tutorial.zh-cn 按照文档的内容写一遍程序 ...
- web.py学习心得
1.注意判断数字时,如果是get传递的参数,一定要用int转换.不然出错. 2.$var 定义时,冒号后的内容不是python内容,需加上$符号.如$var naviId:$naviId. 3.各个模 ...
- web.py+html+mysql实现web端小系统的问题汇总
利用web.py+html(bootstrap)+mysql实现了一个小型的设备管理系统,在这个过程中遇到很多问题,将问题及解决方案总结如下,有遇到类似问题的同学,希望可以帮到你们. 1.关于中文的编 ...
- mac OS X 配置Python+Web.py+MySQLdb环境
MAC默认支持Python 2.7所以不用安装. 1.安装pip sudo easy_install pip 2.安装Web.py sudo pip install Web.py 3.安装MySQLd ...
- web.py+mysql插入中文提示query = query.encode(charset) UnicodeEncodeError: 'latin-1' codec can't encode characters in position 86-100
对于中文编码的问题,总会出现各种各样恶心的错误,还不知道应该怎么解决,首先,你从最开头就应该关注编码问题,尽量保证所有的编码方式都是一致的 用python+web.py+mysql来写程序,首先要保证 ...
- Python Web.py
安装Web.py root@bt:~# sudo pip install web.py Downloading/unpacking web.py Downloading web.py-0.37.tar ...
- 迁移web.py项目至git@osc的项目演示平台
1. 开启演示平台 选择WSGI,输入应用名称,即是演示网页的网址. 2. web.py代码迁移 将Python的site-packages目录下的web文件夹复制到代码目录下,与网页程序在同一个文件 ...
- web.py网页模板中使用jquery
由于$是web.py针对模板的保留字符,所以在模板文件内不能直接使用$("#id")的格式. 解决办法: 1.$$("#id")可以避免$被误解析 2.jque ...
- WSGI、flup、fastcgi、web.py的关系
Apache/lighttpd: 相当于一个request proxy,根据配置,把不同的请求转发给不同的server处理,例如静态的文件请求自己处理,这个时候它就像一个web server,对于fa ...
- web.py simpletodo 例子
一个很好的例子: 许多新手,特别是从 ASP/PHP/JSP 转过来的同学,经常问下面这几个问题: 所有东西都放在一个 code.py 中呀?我有好多东西该如何部署我的代码? 是不是 /index 对 ...
随机推荐
- angular组件--tips提示功能
将组件封装起来在项目中开发很实用,之前遭遇过一次痛苦的经历,那阵子改的要吐血了.常用的组件封装起来,改公共的地方,往往多处受用. 例如:我在项目中引用 tips.text('加载中...',fals ...
- bzoj 1690: [Usaco2007 Dec]奶牛的旅行——分数规划+spfa判负环
Description 作为对奶牛们辛勤工作的回报,Farmer John决定带她们去附近的大城市玩一天.旅行的前夜,奶牛们在兴奋地讨论如何最好地享受这难得的闲暇. 很幸运地,奶牛们找到了一张详细的城 ...
- Linux Mint---更新软件源
安装完系统之后第一件事情就是更新软件源,为接下来的各种工作作准备,这个也很简单,直接打开software source设置一下, 然后打开software manager更新一下就好了.
- JSP中include指令和include动作浅析
一. JSP工作原理 JSP文件是一种Servlet,其工作方式是先部署源代码后编译为.class文件.JSP会在客户端第一次请求JSP文件时被编译成Servlet,由Servlet处理客户端的请求. ...
- YYH的王国(NOIP模拟赛Round 6)
题目描述 YYH拥有一个有n个城市的国家,编号为1~n.其中城市i到城市j的路径长度为i和j的最小公倍数.现在YYH想建一些高速公路,使得任意两座城市都能通过高速公路直接或间接到达.建造一条高速公路的 ...
- Strlcpy和strlcat——一致的、安全的字符串拷贝和串接函数【转】
转自:http://blog.csdn.net/kailan818/article/details/6731772 英文原文: http://www.gratisoft.us/todd/papers/ ...
- Resin4 自定义端口
1. Resin4配置文件发生了较大变化,分为: app-default.xml web应用配置 cluster-default.xml 集群配置 health.xml -- 非pro版不支持 r ...
- Appium+python自动化8-Appium Python API【转载】
前言: Appium Python API全集,不知道哪个大神整理的,这里贴出来分享给大家. 1.contexts contexts(self): Returns the contexts withi ...
- ajax和json数据
一.Ajax概述 1.什么是同步,什么是异步 同步现象:客户端发送请求到服务器端,当服务器返回响应之前,客户端都处于等待 卡死状态 异步现象:客户端发送请求到服务器端,无论服务器是否返回响应, ...
- corosync基本使用
相关rpm: corosync-2.4.0-4.el6.x86_64.rpm The Corosync Cluster Engine and Application Programming Inter ...