小编fil*_*d13的帖子

使用伪元素创建背景叠加

我的目标是使用任何背景的div,然后使用伪元素创建透明的白色叠加,从而"淡化"div的背景.但是,"叠加"必须在div的内容之下.因此,在以下示例中:

<div class="container">
    <div class="content">
        <h1>Hello, World</h1>
    </div>
</div>

.container {
    background-color: red;
    width: 500px;
    height: 500px;
    position: relative;
}
.content {
    background-color: blue;
    width: 250px;
}
.container::before {
    content:"";
    display: block;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 1;
    background-color: rgba(255, 255, 255, .8);
}
Run Code Online (Sandbox Code Playgroud)

.content div不应该是"下面"的白色覆盖,又名.container::before.

我宁愿不必使用z-index.content,但我可以的,如果这是唯一的解决方案.

最终目标:应该覆盖红色而文本和蓝色不应该覆盖.

JS小提琴:http://jsfiddle.net/1c5j9n4x/

html css pseudo-element

30
推荐指数
1
解决办法
4万
查看次数

Apache Airflow DAG无法导入本地模块

我似乎不明白如何将模块导入到apache airflow DAG定义文件中.我想这样做是为了能够创建一个库,例如,使用相似的设置声明任务更简洁.

这是我能想到的最简单的例子,它复制了这个问题:我修改了气流教程(https://airflow.apache.org/tutorial.html#recap),只需导入一个模块并从该模块运行一个定义.像这样:

目录结构:

- dags/
-- __init__.py
-- lib.py
-- tutorial.py
Run Code Online (Sandbox Code Playgroud)

tutorial.py:

"""
Code that goes along with the Airflow located at:
http://airflow.readthedocs.org/en/latest/tutorial.html
"""
from airflow import DAG
from airflow.operators.bash_operator import BashOperator
from datetime import datetime, timedelta

# Here is my added import
from lib import print_double

# And my usage of the imported def
print_double(2)

## -- snip, because this is just the tutorial code, 
## i.e., some standard DAG defintion stuff --
Run Code Online (Sandbox Code Playgroud)

print_double 只是一个简单的def,它将你给它的任何输入乘以2,并打印结果,但显然这甚至不重要,因为这是一个导入问题. …

python airflow apache-airflow

16
推荐指数
2
解决办法
9977
查看次数

jQuery .ajax() - 向POST请求添加查询参数?

要使用jQuery AJAX将查询参数添加到URL,请执行以下操作:

$.ajax({
  url: 'www.some.url',
  method: 'GET',
  data: {
      param1: 'val1'
  }
)}
Run Code Online (Sandbox Code Playgroud)

这会产生一个像url的网址 www.some.url?param1=val1

当方法是POST时,我该怎么做?在这种情况下,data不再作为查询参数附加 - 它构成了请求的主体.

我知道我可以在ajax请求之前手动将params手动附加到url,但我只是有这种唠叨的感觉,我错过了一些明显的方法,这比我需要执行的~5行短在ajax调用之前.

javascript ajax jquery json

12
推荐指数
1
解决办法
9237
查看次数

为什么 pip 安装了不兼容的软件包版本?

我在 Ubuntu 上使用 pip 20.0.2,并从需求文件中安装了一堆需求。出于某种原因,pip 决定安装idna==2.9(link),即使这与我直接列出的依赖项之一不兼容。所以我python -m pipdeptree -r在我正在安装所有东西的 virtualenv 中使用,我看到以下列出了idna

idna==2.9                                         
  - cryptography==2.3.1 [requires: idna>=2.1]
  - requests==2.22.0 [requires: idna>=2.5,<2.9]
    - requests-oauthlib==1.3.0 [requires: requests>=2.0.0]
      - social-auth-core==3.2.0 [requires: requests-oauthlib>=0.6.1]
        - social-auth-app-django==2.1.0 [requires: social-auth-core>=1.2.0]
    - responses==0.10.9 [requires: requests>=2.0]
    - social-auth-core==3.2.0 [requires: requests>=2.9.1]                           
      - social-auth-app-django==2.1.0 [requires: social-auth-core>=1.2.0]
Run Code Online (Sandbox Code Playgroud)

正如我们所见,我的两个直接依赖项(cryptographyrequests)是 require idna。根据那些,看起来 pip 应该决定安装2.8,因为它是满足约束的最新版本。

为什么 pip 而不是安装idna2.9,如该输出的第一行所示,以及运行时的此错误消息pip install -r requirements.txt

ERROR: requests 2.22.0 has requirement idna<2.9,>=2.5, but …
Run Code Online (Sandbox Code Playgroud)

python pip

8
推荐指数
1
解决办法
6899
查看次数

在较大的Django迁移中只进行一次操作来进行数据迁移是否安全?

我正在处理我认为是一个常见问题:我已经意识到模型的现有模型字段Foo将更好地作为Bar具有外键的完全单独的模型Foo.因此,我们需要进行架构迁移.但更重要的是,由于模型领域中已有数据Foo,我们需要在删除该字段之前进行数据迁移.

所以我们发现有三个不同的步骤:

  1. 创建新表 Bar
  2. 将现有数据迁移Foo到新表中Bar
  3. 删除现有字段 Foo

首先,我在models.py中进行所有必需的模型更改,然后自动生成迁移.一切看起来都不错,除了我们将丢失该字段中的所有数据,因此我需要添加一个额外的操作来处理数据迁移(RunPython).我最终会得到以下内容:

def do_data_migration(apps, schema_editor):
    # Migrate data from Foo to Bar

class Migration(migrations.Migration):

    dependencies = [ 
        ('exampleapp', 'migration_003'),
    ]   

    operations = [ 
        migrations.CreateModel(
            # Create the new model Bar
        ),  
        migrations.AddField(
            # Add the foreign key field to model Foo
        ),  
        migrations.RunPython(
            do_data_migration
        ),
        migrations.RemoveField(
            # Remove the old field from Foo
        ),  
    ]
Run Code Online (Sandbox Code Playgroud)

将数据迁移作为迁移中的几个操作之一运行是否安全?我担心的是,有任何类型的锁定正在进行,或者RunPython传递到的应用程序注册表是否do_data_migration …

python django

7
推荐指数
1
解决办法
867
查看次数

如何用酶测试反应路由器链接?

我看到很多与此类似的问题,但似乎都过时或令人难以置信。

我有一个React组件,其中包含一个React Router Link组件,如下所示:

export default class Home extends Component {                                      
  render() {                                                                       
    return (                                                                       
      <div className="Home">  
        <Link to="/mission">Begin</Link>                                           
      </div>                                              
    );                                                                             
  }                                                                                
}
Run Code Online (Sandbox Code Playgroud)

然后,我尝试使用Jest 非常简单地测试该Home组件是否包含Link具有to=/mission属性的组件。因此,根据Testing React Router文档,我尝试了多种测试,但是此代码最简洁地演示了我要实现的目标(示例为简单起见,使用jest酶):

it('includes link to Mission scene', () => {                                       
  const home = shallow(<MemoryRouter><Home /></MemoryRouter>);                                                              
  expect(home).toContainReact(<Link to="/mission">Begin</Link>)                    
});
Run Code Online (Sandbox Code Playgroud)

显然,该代码有几个问题,其中最重要的是错误:

Warning: Failed context type: The context `router` is marked as required in `Link`, but its value is `undefined`.
Run Code Online (Sandbox Code Playgroud)

但是请注意关键点:我想浅化渲染(如果可能的话)Home组件,以便隔离测试该组件。同时,我尝试将其包装在MemoryRouter或以某种方式使上下文就位,以便可以测试 …

testing unit-testing reactjs react-router enzyme

7
推荐指数
1
解决办法
6774
查看次数

Django 在管理中根据另一个模型字段验证一个模型字段

假设一个模型有两个 DateTimeFields:

class Tourney(models.Model):
    registration_deadline = models.DateTimeField()
    start_date = models.DateTimeField()
Run Code Online (Sandbox Code Playgroud)

当用户试图从Django管理内提交锦标赛,我怎么能测试registration_deadline是之前start_date保存到数据库之前,如果有错误,当然通知用户在线,就像Django的想,如果有任何其他验证错误?

基本上,我正在寻找自定义管理员验证。Django 文档的这一部分很接近,但似乎用于表单。如何在 Django 的管理员中执行“清理和验证相互依赖的字段”?即使只是指向文档中正确位置的指针也足够了。

编辑:我认为它与验证器有关,但它们似乎只能测试单个值,而不是同时测试两个值...

python django validation

4
推荐指数
1
解决办法
1529
查看次数

如何阅读csv django http响应

在视图中,我使用简单的csv编写器创建一个完全由csv组成的Django HttpResponse对象:

response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename="foobar.csv"'

writer = csv.writer(response)

    table_headers = ['Foo', 'Bar']
    writer.writerow(table_headers)

    bunch_of_rows = [['foo', 'bar'], ['foo2', 'bar2']]
    for row in bunch_of_rows:
        writer.writerow(row)

return response
Run Code Online (Sandbox Code Playgroud)

在单元测试中,我想测试这个csv的某些方面,所以我需要阅读它.我试着这样做:

response = views.myview(args)

reader = csv.reader(response.content)

headers = next(reader)
row_count = 1 + sum(1 for row in reader)

self.assertEqual(row_count, 3) # header + 1 row for each attempt
self.assertIn('Foo', headers)
Run Code Online (Sandbox Code Playgroud)

但是测试失败了以下内容headers = next(reader):

nose.proxy.Error: iterator should return strings, not int (did you open the file in text …
Run Code Online (Sandbox Code Playgroud)

python csv django

4
推荐指数
1
解决办法
1973
查看次数

为什么 pytest-django 找不到 manage.py?

我有一个这样的项目结构:

setup.cfg
integration_tests/
  |----tests.py
src/
  |----manage.py
  |----my_django_app/
Run Code Online (Sandbox Code Playgroud)

还有一个 setup.cfg :

[tool:pytest]
addopts=--tb=short --strict -ra
DJANGO_SETTINGS_MODULE = my_django_app.settings
env = 
    APP_ENV=testing
    USE_SQLITE_DB=True
Run Code Online (Sandbox Code Playgroud)

但是当我导航到该目录结构的顶部并运行时pytest,我得到以下信息:

“pytest-django 找不到 Django 项目(找不到 manage.py 文件)。你必须明确地将你的 Django 项目添加到 Python 路径中才能被选中。”

如果我转而导航到/src/并运行pytest,则测试运行没有问题,但很明显,因为我在一个级别上没有运行任何集成测试。

根据文档,它似乎应该从您运行的位置向下钻取pytest以尝试查找manage.pyhttps : //pytest-django.readthedocs.io/en/latest/managing_python_path.html#automatic-looking-for-of- Django 项目

如果不是这种情况,那么是否有某种方法可以在 setup.cfg 中配置设置以添加src/到 PYTHONPATH?文档src/中使用 pip 以可编辑模式安装的建议在我们的环境中并不能真正站得住脚。

python django pytest pytest-django

4
推荐指数
1
解决办法
980
查看次数

盒子阴影在图像上?

小提琴:http://jsfiddle.net/G5FaQ/

我有一个包含在div中的图像.紧邻所述图像的div具有框阴影.我希望div的box-shadow与图像重叠,所以看起来图像是它所处的div的一部分,而不是看起来奇怪地悬停在它上面.我试过z-index,正如你在小提琴中看到的那样,但似乎失败了.

HTML:

<body>

<nav id="navigation">
    <img src="http://web.fildred.com/media/images/blank_logo.jpg" height="150px" width="250px" alt="logo">
</nav>

<div id="content_wrapper">
<!-- InstanceBeginEditable name="content" -->
<section id="content">
    Content.
</section>
<!-- InstanceEndEditable -->
</div>

</div>
</body>
Run Code Online (Sandbox Code Playgroud)

CSS:

body {
    background: #ffd288;    
}

/*Nav*/
#navigation {
    width:100%;
    z-index: 10;
}

.logo {
    z-index: 1; 
}

/*Content Section*/
#content {
    background: #393951;
    height: 2000px;
    z-index: 10;
    -webkit-box-shadow: 0px 0px 20px rgba(0,0,0,.8);
        -moz-box-shadow: 0px 0px 20px rgba(0,0,0,.8);
            box-shadow: 0px 0px 20px rgba(0,0,0,.8);
}
Run Code Online (Sandbox Code Playgroud)

html css

3
推荐指数
1
解决办法
1万
查看次数