我想在Bootstrap中设置一个选中的按钮btn-group:
<div class="btn-toolbar">
<div class="btn-group">
<button type="button" class="btn btn-default">5</button>
<button type="button" class="btn btn-default">6</button>
<button type="button" class="btn btn-default">7</button>
</div>
<div class="btn-group">
<button type="button" class="btn btn-default">8</button>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我如何预先选择选项5?这个答案表明我可以active在按钮上添加类,这确实最初起作用,但是然后单击其他按钮不会停用该按钮,正如我所料.
这是一个小提琴:http://bootply.com/90490
这是active应用类的另一个小提琴,显示为什么它不是正确的解决方案:http://bootply.com/90491 - 单击任何其他按钮,按钮5仍然保持活动状态.
正如标题所说......我不确定Django迁移是否应该存在于源代码管理中.
对于:
反对:
我在Django 1.8工作.我ALLOWED_HOSTS在本地和部署设置中设置如下:
ALLOWED_HOSTS = ['localhost', 'my.deployed.url']
Run Code Online (Sandbox Code Playgroud)
这样我就不需要更改已部署版本中的设置.(这不是很难做到的,这种方式很方便.)
是否有任何安全原因导致我不应该localhost在远程服务器上部署的设置上拥有该设置?
从文档我不认为有,但只是想检查.
我正在使用Mapbox GL JS版本0.32.有没有办法将地图导出为高分辨率的PNG或PDF?
显然,我可以截图,但如果有更正式的方式会很好.
我找到了这个回购,但它看起来很旧,并不清楚它是如何工作的.
我尝试使用该preserveDrawingBuffer选项:
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/light-v9',
minZoom: 4,
maxZoom: 14,
center: [-2.0, 53.3],
preserveDrawingBuffer: true
});
console.log(map.getCanvas().toDataURL());
Run Code Online (Sandbox Code Playgroud)
这会在控制台中输出一个长数据URL,但将其复制并粘贴到base64转换器中似乎只会产生一个空图像.
更新:这是我的新代码,完整:
mapboxgl.accessToken = 'pk.eyXXX';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/light-v9',
minZoom: 4,
maxZoom: 14,
center: [-2.0, 53.3],
preserveDrawingBuffer: true
});
var dpi = 300;
Object.defineProperty(window, 'devicePixelRatio', {
get: function() {return dpi / 96}
});
map.on('load', function () {
var content = …Run Code Online (Sandbox Code Playgroud) 很抱歉,如果已经回答了这个问题,但是如果是这样的话我就找不到了.
我想在Javascript中找到图像文件的高度和宽度.我实际上不需要在页面中显示图像,只需要显示高度和宽度.
目前我已经得到了以下代码,但它返回高度和宽度0(在Mozilla 5中).
var img = new Image();
img.src = "./filename.jpg";
var imgHeight = img.height;
var imgWidth = img.width;
alert("image height = " + imgHeight + ", image width = " + imgWidth);
Run Code Online (Sandbox Code Playgroud)
该文件肯定存在,它与HTML在同一目录中,并且它没有高度和宽度0 :)
我究竟做错了什么?
我正在尝试使用以下方法重置Django中的数据库:
python manage.py reset app
Run Code Online (Sandbox Code Playgroud)
但是得到以下错误:
Error: Error: app couldn't be reset. Possible reasons:
* The database isn't running or isn't configured correctly.
* At least one of the database tables doesn't exist.
* The SQL was invalid.
Hint: Look at the output of 'django-admin.py sqlreset app'. That's the SQL this command wasn't able to run.
The full error: cannot drop table app_record because other objects depend on it
HINT: Use DROP ... CASCADE to drop the dependent objects too. …Run Code Online (Sandbox Code Playgroud) 这让我完全疯了,我已经挣扎了好几个小时.任何帮助将非常感激.
我正在使用PyQuery 1.2.9(它构建在它之上lxml)来抓取这个URL.我只想获得该.linkoutlist部分中所有链接的列表.
这是我的全部要求:
response = requests.get('http://www.ncbi.nlm.nih.gov/pubmed/?term=The%20cost-effectiveness%20of%20mirtazapine%20versus%20paroxetine%20in%20treating%20people%20with%20depression%20in%20primary%20care')
doc = pq(response.content)
links = doc('#maincontent .linkoutlist a')
print links
Run Code Online (Sandbox Code Playgroud)
但是返回一个空数组.如果我使用此查询:
links = doc('#maincontent .linkoutlist')
Run Code Online (Sandbox Code Playgroud)
然后我得到这个HTML:
<div xmlns="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" class="linkoutlist">
<h4>Full Text Sources</h4>
<ul>
<li><a title="Full text at publisher's site" href="http://meta.wkhealth.com/pt/pt-core/template-journal/lwwgateway/media/landingpage.htm?issn=0268-1315&volume=19&issue=3&spage=125" ref="itool=Abstract&PrId=3159&uid=15107654&db=pubmed&log$=linkoutlink&nlmid=8609061" target="_blank">Lippincott Williams & Wilkins</a></li>
<li><a href="http://ovidsp.ovid.com/ovidweb.cgi?T=JS&PAGE=linkout&SEARCH=15107654.ui" ref="itool=Abstract&PrId=3682&uid=15107654&db=pubmed&log$=linkoutlink&nlmid=8609061" target="_blank">Ovid Technologies, Inc.</a></li>
</ul>
<h4>Other Literature Sources</h4>
...
</div>
Run Code Online (Sandbox Code Playgroud)
所以父选择器确实返回带有大量<a>标签的HTML .这似乎也是有效的HTML.
更多的实验表明lxml xmlns由于某种原因不喜欢开放div上的属性.
我如何在lxml中忽略它,并像普通HTML一样解析它?
更新:尝试ns_clean,仍然失败:
parser = etree.XMLParser(ns_clean=True)
tree = etree.parse(StringIO(response.content), …Run Code Online (Sandbox Code Playgroud) 我正在使用Python 2研究Debian Jessie.为什么Python不能environ看到在bash中可见的环境变量?
# echo $SECRET_KEY
xxx-xxx-xxxx
# python
>>> from os import environ
>>> environ["SECRET_KEY"]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/root/.virtualenvs/prescribing/lib/python2.7/UserDict.py", line 23, in __getitem__
raise KeyError(key)
KeyError: 'SECRET_KEY'
Run Code Online (Sandbox Code Playgroud)
我使用/etc/environment- 设置这些环境变量- 不确定是否相关:
SECRET_KEY=xxx-xxx-xxx
Run Code Online (Sandbox Code Playgroud)
我不得不跑去source /etc/environment看看他们,我觉得这很奇怪.
更新:printenv SECRET_KEY什么都不产生,所以我猜SECRET_KEY是shell不是环境变量.
我想将两个Pandas数据帧合并在一起并控制新列值的名称.
我最初是从CSV文件创建的数据帧.原始CSV文件如下所示:
# presents.csv
org,name,items,spend...
12A,Clerkenwell,151,435,...
12B,Liverpool Street,37,212,...
...
# trees.csv
org,name,items,spend...
12A,Clerkenwell,0,0,...
12B,Liverpool Street,2,92,...
...
Run Code Online (Sandbox Code Playgroud)
现在我有两个数据框:
df_presents = pd.read_csv(StringIO(presents_txt))
df_trees = pd.read_csv(StringIO(trees_txt))
Run Code Online (Sandbox Code Playgroud)
我想将它们合并在一起以获得最终数据帧,连接org和name值,然后使用适当的前缀为所有其他列添加前缀.
org,name,presents_items,presents_spend,trees_items,trees_spend...
12A,Clerkenwell,151,435,0,0,...
12B,Liverpool Street,37,212,2,92,...
Run Code Online (Sandbox Code Playgroud)
我一直在阅读有关合并和加入的文档.这似乎正确合并并产生正确的列数:
ad = pd.DataFrame.merge(df_presents, df_trees,
on=['practice', 'name'],
how='outer')
Run Code Online (Sandbox Code Playgroud)
但接下来会给print list(aggregate_data.columns.values)我看以下几列:
[org', u'name', u'spend_x', u'spend_y', u'items_x', u'items_y'...]
Run Code Online (Sandbox Code Playgroud)
如何重命名spend_x是presents_spend等?
我有一个在month列上索引的DataFrame (df = df.set_index('month')如果相关则设置使用):
org_code ratio_cost
month
2010-08-01 1847 8.685939
2010-08-01 1848 7.883951
2010-08-01 1849 6.798465
2010-08-01 1850 7.352603
2010-09-01 1847 8.778501
Run Code Online (Sandbox Code Playgroud)
我想添加一个名为的新列quantile,它将根据该月的值为每行分配一个分位数值ratio_cost.
所以上面的例子可能如下所示:
org_code ratio_cost quantile
month
2010-08-01 1847 8.685939 100
2010-08-01 1848 7.883951 66.6
2010-08-01 1849 6.798465 0
2010-08-01 1850 7.352603 33.3
2010-09-01 1847 8.778501 100
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?我试过这个:
df['quantile'] = df.groupby('month')['ratio_cost'].rank(pct=True)
Run Code Online (Sandbox Code Playgroud)
但我明白了KeyError: 'month'.
更新:我可以重现这个bug.
这是我的CSV文件:http://pastebin.com/raw/6xbjvEL0
这是重现错误的代码:
df = pd.read_csv('temp.csv')
df.month = pd.to_datetime(df.month, unit='s')
df = …Run Code Online (Sandbox Code Playgroud) python ×4
django ×3
pandas ×2
bash ×1
dataframe ×1
html ×1
html-parsing ×1
javascript ×1
lxml ×1
mapbox ×1
mapbox-gl-js ×1
pyquery ×1
sql ×1