我有两个组成部分.
我试图从Parent调用child的方法,我尝试了这种方式,但无法得到结果
class Parent extends Component {
render() {
return (
<Child>
<button onClick={Child.getAlert()}>Click</button>
</Child>
);
}
}
class Child extends Component {
getAlert() {
alert('clicked');
}
render() {
return (
<h1 ref="hello">Hello</h1>
);
}
}
Run Code Online (Sandbox Code Playgroud)
有没有办法从父母那里调用孩子的方法?
注意:Child和Parent组件位于两个不同的文件中
我有几个docker-compose.yml文件,我想使用相同的Dockerfile,稍有变化.所以我想将一个参数传递给该Dockerfile,以便我可以根据变量设置的值做一些略微不同的事情.
到目前为止我尝试过的
docker-compose-A.yml文件
version: '2'
services:
django:
build:
context: .
dockerfile: ./docker/Dockerfile
args:
- SOMETHING=foo
Run Code Online (Sandbox Code Playgroud)
docker-compose-B.yml文件
version: '2'
services:
django:
build:
context: .
dockerfile: ./docker/Dockerfile
args:
- SOMETHING=bar
Run Code Online (Sandbox Code Playgroud)
我有一个dockerfile我想使用SOMETHING.例如
# Dockerfile
RUN echo $SOMETHING
Run Code Online (Sandbox Code Playgroud)
这不起作用.SOMETHING未传递给dockerfile.
我这样做不正确还是这不是预期用途?
有没有其他方法可以从docker-compose.yml文件将变量传递给Dockerfile?
任何反馈都表示赞赏.谢谢
我需要在docker-compose.yml中添加一些路径到我的PATH
在docker-compose.yml中我试过了
app:
...
environment:
- PATH /code/project
Run Code Online (Sandbox Code Playgroud)
然而,这只会覆盖现有的PATH - 而我想添加到现有的PATH
我最近遇到了这个,并想知道是什么&django
意思
version: '2'
services:
django: &django
Run Code Online (Sandbox Code Playgroud)
在与此相关的文档中看不到任何内容.
提前致谢
我正在学习一些JS,我希望有人可以用简单的术语向我解释Object.getPrototypeOf()
vs 之间的区别.prototype
function ParentClass() {}
function ChildClass() {}
ChildClass.prototype = new ParentClass();
var mychild = new ChildClass();
var myparent = new ParentClass();
# .getPrototypeOf
Object.getPrototypeOf(ChildClass.prototype) // ParentClass {}
Object.getPrototypeOf(mychild) // ParentClass {}
Object.getPrototypeOf(ParentClass.prototype) // {}
Object.getPrototypeOf(myparent) // ParentClass {}
# .prototype
ParentClass.prototype // ParentClass {}
myparent.prototype // undefined
ChildClass.prototype // ParentClass {}
mychild.prototype // undefined
Run Code Online (Sandbox Code Playgroud)
所以看起来你只能在构造函数上调用.prototype?
还有其他差异吗?
我一直在尝试django-channels,包括阅读文档和玩弄例子.
我希望能够通过将新实例保存到数据库来触发向单个用户发送消息.
我的用例是创建一个新的通知(通过芹菜任务),一旦通知保存,将此通知发送给单个用户.
这听起来有可能(来自django-channels docs)
...关键部分是你可以运行代码(以及发送频道)以响应任何事件 - 包括你创建的事件.您可以触发模型保存,其他传入消息或视图和表单内的代码路径.
然而,进一步阅读文档和玩django-channels示例,我无法看到我如何做到这一点.数据绑定和liveblog示例演示了发送到组,但我看不到如何发送给单个用户.
任何建议将不胜感激.
我想使用Splinter测试自动完成框。我需要将“向下”和“输入”键发送到浏览器,但是这样做很麻烦。
我目前正在寻找一个输入框,并在该框中成功输入“ tes”
context.browser.find_by_xpath(\\some\xpath\).first.type('tes')
Run Code Online (Sandbox Code Playgroud)
我接下来要做的是向浏览器发送一些键,特别是“向下”键(选择第一个自动完成建议),然后发送“ enter”键选择该自动完成元素。
我已经尝试了广泛的搜索,但不知道如何执行此操作。
我什至尝试了一些JavaScript
script = 'var press = jQuery.Event("keypress"); press.keyCode = 34; press.keyCode = 13;'
context.browser.execute_script(script)
Run Code Online (Sandbox Code Playgroud)
但这不幸的是没有做任何事情
我正在使用的软件包:
django 1.6 django-behave == 0.1.2碎片0.6
当前配置是:
从splinter.browser import从django.test.client import浏览器import Client
context.browser = Browser('chrome')
context.client = Client()
Run Code Online (Sandbox Code Playgroud) 我将 Docker 配置为使用 docker-compose.yml 运行 Postgres 和 Django,并且工作正常。
我遇到的问题是 Selenium 无法连接到 Django liveserver。
现在,django 必须访问 selenium 来控制浏览器,而 selenium 必须访问 django 来访问服务器,这是有道理的(至少对我来说)。
我尝试使用 docker 'ambassador' 模式,使用以下 docker-compose.yml 配置:https: //github.com/docker/compose/issues/666
postgis:
dockerfile: ./docker/postgis/Dockerfile
build: .
container_name: postgis
django-ambassador:
container_name: django-ambassador
image: cpuguy83/docker-grand-ambassador
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
command: "-name django -name selenium"
django:
dockerfile: ./docker/Dockerfile-dev
build: .
command: python /app/project/manage.py test my-app
container_name: django
volumes:
- .:/app
ports:
- "8000:8000"
- "8081:8081"
links:
- postgis
- "django-ambassador:selenium"
environment:
- SELENIUM_HOST=http://selenium:4444/wd/hub
selenium:
container_name: selenium
image: …
Run Code Online (Sandbox Code Playgroud) 按照文档和Demo Django项目https://github.com/celery/celery/tree/3.1/examples/django
项目结构
piesup2
|
piesup2
| |__init__.py
| |celery.py
| |settings.py
| |urls.py
reports
|tasks.py
|models.py
|etc....
Run Code Online (Sandbox Code Playgroud)
我的守则
piesup2/celery.py
from __future__ import absolute_import
import os
from celery import Celery
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'piesup2.settings')
from django.conf import settings # noqa
app = Celery('piesup2')
# Using a string here means the worker will not have to
# pickle the object when using Windows.
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request)) …
Run Code Online (Sandbox Code Playgroud)