我正在创建一个从网站上下载mp3文件的扩展程序.我试图通过创建一个带有mp3文件链接的新选项卡来做到这一点,但chrome继续在播放器中打开它而不是下载它.有什么办法可以创建一个弹出窗口来要求用户"另存为"文件吗?
原文:我最近开始从我的一些旧代码中获取MySQL OperationalErrors,似乎无法追溯问题.由于它之前的工作,我认为它可能是一个破坏了一些东西的软件更新.我正在使用带有nginx的django runfcgi的python 2.7.这是我的原始代码:
views.py
DBNAME = "test"
DBIP = "localhost"
DBUSER = "django"
DBPASS = "password"
db = MySQLdb.connect(DBIP,DBUSER,DBPASS,DBNAME)
cursor = db.cursor()
def list(request):
statement = "SELECT item from table where selected = 1"
cursor.execute(statement)
results = cursor.fetchall()
Run Code Online (Sandbox Code Playgroud)
我尝试了以下内容,但它仍然无效:
views.py
class DB:
conn = None
DBNAME = "test"
DBIP = "localhost"
DBUSER = "django"
DBPASS = "password"
def connect(self):
self.conn = MySQLdb.connect(DBIP,DBUSER,DBPASS,DBNAME)
def cursor(self):
try:
return self.conn.cursor()
except (AttributeError, MySQLdb.OperationalError):
self.connect()
return self.conn.cursor()
db = DB()
cursor = db.cursor() …Run Code Online (Sandbox Code Playgroud) 我需要在用python编写的程序中导入readline功能.我目前正在使用2.7版本,我见过的第三方软件包只能使用2.6版本.有没有人知道使用Python 2.7的Windows的第三方readline包?
我正在尝试使用此代码专门从域中获取cookie:
<script language="javascript" type="text/javascript">
var ID;
function getCookies(domain, name) {
chrome.cookies.get({"url": domain, "name": name}, function(cookie) {
ID = cookie.value;
});
}
getCookies("http://www.example.com", "id")
alert(ID);
</script>
Run Code Online (Sandbox Code Playgroud)
问题是警报总是说未定义.但是,如果我改变了
ID = cookie.value;
Run Code Online (Sandbox Code Playgroud)
至
alert(cookie.value);
Run Code Online (Sandbox Code Playgroud)
它工作正常.如何保存以后使用的值?
更新:如果我在脚本运行后从chrome控制台调用alert(ID),它似乎有效.如何设置我的代码以等到chrome.cookies.get完成运行?
我有这种格式的网址:
http:\/\/example.example.ru\/u82651140\/audio\/song.mp3
如何从字符串中删除多余的"\"?我尝试过string.replace("\",""),但似乎没有做任何事情.如果你能给我一个能抓住这个的JavaScript正则表达式,那也可以.我只需要能够在另一个字符串里面捕获这个字符串.
我正在尝试使用Mongoose存储对象字典.意识到我使用Mixed类型丢失了保存更改检测,我希望我可以创建一个不需要Mixed类型的模式.
有很多为对象数组创建模式的示例,但不是对象的字典.是否有可能做到这一点?
格式:
{
ObjectId : {
"attempts" : {
"response" : String,
"timestamp" : Date
},
"complete" : Boolean
}
}
Run Code Online (Sandbox Code Playgroud) 出于某种原因,django没有提供我的静态文件.
我已经看过这个问题的一堆修复,但我还没有找到解决方案.
这是我的配置:
urls.py
urlpatterns = patterns('',
(r'^$', index),
(r'^ajax/$', ajax),
(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': path.join(path.dirname(__file__), 'static')}),
)
Run Code Online (Sandbox Code Playgroud)
settings.py
STATIC_ROOT = '/home/aurora/Code/django/test/static/'
STATIC_URL = '/static/'
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
# 'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)
Run Code Online (Sandbox Code Playgroud)
当我导航到http://localhost:8000/static/css/default.css
我时出现此错误:'css/default.css' could not be found
当我导航到http://localhost:8000/static/
我时出现此错误:Directory indexes are not allowed here.
看起来静态目录已被映射出来,但子目录却没有.
反正有没有得到iframe加载页面的源代码?我不想更改任何代码,我只想阅读它.我还需要能够使用javascript/html获得此功能.
目前,我正在使用记事本和Chrome控制台的组合对我的google-chrome-extensions进行编码.我100%确定有更好的方法来编程这些扩展.人们使用什么环境?
我正在尝试用PHP开始编程.我找到了这个例子"Hello,World" PHP页面.
这是代码:
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Hello World</p>'; ?>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
但是,而不是显示:
Hello World
Run Code Online (Sandbox Code Playgroud)
它显示:
Hello World
'; ?>
Run Code Online (Sandbox Code Playgroud)
查看源显示
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Hello World</p>'; ?>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
代替
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<p>Hello World</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
所以它似乎没有被Chrome解析.是什么导致了这个问题?