我正在尝试在我的 macOS 中安装virtualenvwrapper(不是pyenv-virtualenvwrapper)(使用 zsh)。我用来pyenv管理多个 python 版本并pipx安装 CLI 东西。
我正在使用Python 3.8.1
$ pyenv versions
system
2.7.17
* 3.8.1 (set by /Users/my_user/.pyenv/version)
Run Code Online (Sandbox Code Playgroud)
我用 pipx 安装了 virtualenvwrapper
$ pipx install virtualenvwrapper
$ pipx list
venvs are in /Users/my_user/.local/pipx/venvs
apps are exposed on your $PATH at /Users/my_user/.local/bin
package sshuttle 0.78.5, Python 3.8.1
- sshuttle
package virtualenv 20.0.15, Python 3.8.1
- virtualenv
package virtualenvwrapper 4.8.4, Python 3.8.1
- virtualenvwrapper.sh
- virtualenvwrapper_lazy.sh
Run Code Online (Sandbox Code Playgroud)
我插入了.zshrc以下几行:
export WORKON_HOME=$HOME/.virtualenvs
source …Run Code Online (Sandbox Code Playgroud) 我正在使用 VSCode 远程开发在 Docker 容器内运行和调试 django 项目。在我的中devcontainer.json我转发了端口8000
"forwardPorts": [8000],
Run Code Online (Sandbox Code Playgroud)
这是我的launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Django",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/myapp/manage.py",
"args": [
"runserver",
"0.0.0.0:8000"
],
"django": true
}
]
}
Run Code Online (Sandbox Code Playgroud)
当我使用这样的配置开始调试时,我看到转发了 4 个端口:端口 8000 和其他 3 个随机高端口
8000 -> localhost:8000 (the only one I'd expect to see)
34075 -> 127.0.0.1:34075
37301 -> 127.0.0.1:37301
42129 -> 127.0.0.1:42129
Run Code Online (Sandbox Code Playgroud)
我想知道为什么这三个端口被转发以及如何避免它。
我在基于 FastAPI 的项目中使用Pydantic 设置管理。我有Settings一堂这样的课:
class Settings(BaseSettings):
FOO: str = ''
BAR: int = 0
class Config:
env_file = "path/to/.my_env_file")
env_nested_delimiter = "__"
Run Code Online (Sandbox Code Playgroud)
该文件path/to/.my_env_file包含FOO和BAR值。
在测试期间,我需要有选择地修补Settings,并且我不想从 中读取任何内容path/to/.my_env_file。例如,
path/to/.my_env_file
FOO=i_do_not_wanna_read_this
BAR=100
Run Code Online (Sandbox Code Playgroud)
我的测试文件:
@lru_cache()
def get_settings():
return Settings()
def get_settings_override() -> Settings:
return Settings(
FOO = 'foo'
)
app.dependency_overrides[get_settings] = get_settings_override
Run Code Online (Sandbox Code Playgroud)
我想使用FOO='foo'BAR 的默认值 和 运行测试(即,BAR=0忽略 的内容path/to/.my_env_file。在上面的代码中,我得到FOO='foo'但仍然从(即,)BAR读取path/to/.my_env_fileBAR=100
有没有直接的方法来处理这个问题?
我是Angular的新手.我有一个带有导航栏的单页应用程序,它映射到一些html"部分".每个部分都可视化,通过Angular指令监视变量的状态ng-show.
第一次加载后,我的所有部分都被加载,所有HTML都在浏览器中.现在我可以做一些操作并在sessionStorage中保存一个对象.但Angular表达式提到它不会加载新数据!我想在我的表达式和会话存储之间进行经典的数据绑定.我怎样才能做到这一点?
这里有一段我的html:
<div class="container" ng-show="panels.isSelected(2)" ng-controller="DataController as pdc">
{{pdc.myData.property_foo}}
</div>
Run Code Online (Sandbox Code Playgroud)
这是从sessionStorage加载数据的控制器
.controller('DataController', ['$window', function($window) {
pdc = this;
//myData is an object
pdc.myData = JSON.parse($window.sessionStorage.getItem("myData"));
}]);
Run Code Online (Sandbox Code Playgroud)
Angular myData仅在第一次加载页面时评估值,而不是每次myData更改时触发表达式的新评估...这是我的问题......
编辑:我在此plnkr中模拟我的问题http://plnkr.co/edit/vG1IGOPsJlbUPOzYsY03?p=preview如您所见,当您按更新时,会话存储中显示的值不会更新.您只能通过刷新页面来查看新值.
我正在开展一个PythonOOP项目.我必须处理MongoDB交互,但我不想使用ODM类似的mongoengine.
我想要的是与所有必须与之交互的类共享一个主要的Mongo连接.我认为使用主DB类可能是一个好主意,我有两个解决方案.
解决方案 类级别的连接
mydb.py
from pymongo import MongoClient
class MyMongoDB(object):
_client = MongoClient('localhost', 27017)
db = _client['name_of_the_db']
Run Code Online (Sandbox Code Playgroud)
在其他课程中:
from mydb import MyMongoDB
class Foo(object):
_db_collection = MyMongoDB.db.foo_collection
def __init__(self):
pass
def set_data(self, data):
Foo._db_collection.insert_one(data)
Run Code Online (Sandbox Code Playgroud)
解决方案 实例级别的连接
mydb.py
from pymongo import MongoClient
class MyMongoDB(object):
def __init__(self):
_client = MongoClient('localhost', 27017)
db = _client['name_of_the_db']
Run Code Online (Sandbox Code Playgroud)
在其他课程中:
from mydb import MyMongoDB
class Foo(object):
_db_collection = MyMongoDB().db.foo_collection
def __init__(self):
pass
def set_data(self, data):
Foo._db_collection.insert_one(data) …Run Code Online (Sandbox Code Playgroud) 所以,我正在尝试更改传单地图中的markercluster图标的颜色.我只想更改继承其余默认属性的颜色(即形状,文本属性等).
在这个例子中,有类似于我想要的东西,但它们定义了一个全新的CSS类,而没有使用默认的图标样式.我需要的是这样的东西,但有自定义颜色:
我知道我必须自定义iconCreateFunction.我正在尝试这种方式:
CSS
.foo { background-color: red;}
.bar { background-color: blue;}
Run Code Online (Sandbox Code Playgroud)
JavaScript的
var markers = L.markerClusterGroup({
iconCreateFunction: function(cluster) {
// here there is a piece code that determines the value of the variable 'class_name' is either foo or bar
return L.divIcon({ className: "marker-cluster-medium "+class_name});
}
});
Run Code Online (Sandbox Code Playgroud)
不幸的是,该解决方案不起作用并导致丑陋的图标渲染.
如何更改默认标记集群图标的颜色?
我在 macOS 上使用 VS 代码 + git 版本 2.20.1。有时,当我在各个分支之间切换时,其他分支的文件错误地保留在当前分支中。
这些文件不存在.gitignore并且它们不是未提交的更改。
例如,如果我有那些提交的文件:
如果我branch_a在 VS Code 中签出,我提交所有更改,然后切换到branch_b,我仍然file1在我的工作目录中。
奇怪的file1是,git 以某种方式“不可见”。实际上,这不被视为对 的潜在更改branch_b。即使它实际上在文件系统上,它也会被忽略。让我从命令行的角度澄清这一点。
$ [git: branch_a] ls
file1 file2
$ [git: branch_a] git status
nothing to commit, working tree clean
$ git checkout branch_b
Switched to branch 'branch_b'
Your branch is up to date with 'origin/branch_b'.
$ [git: branch_b] ls
file1 file2
Run Code Online (Sandbox Code Playgroud)
然而,file1不应该在这里,但是……
$ [git: branch_b] git status
nothing …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 traefik v2.2 和 GoDaddy 建立通配符证书机制。我想要做的是为 URL 模式 *.example.org 生成有效的证书。这是我的 docker-compose:
version: '3.7'
services:
traefik:
image: traefik:v2.2
container_name: traefik
restart: always
env_file:
- .provider.env
# .provider.env contains `GODADDY_API_KEY` and `GODADDY_API_SECRET`
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./tls-certificates:/tls-certificates
ports:
# http
- 8080:80
# https
- 443:443
command:
- --api.dashboard=true
- --providers.docker=true
- --providers.docker.exposedbydefault=false
- --providers.docker.network=proxy
- --entrypoints.webinsecure.address=:80
- --entrypoints.websecure.address=:443
# --certificatesresolvers.<name> Certificates resolvers configuration
# ACME V2 supports wildcard certificates.
# Wildcard certificates can only be generated through a DNS-01 challenge.
- …Run Code Online (Sandbox Code Playgroud) 有没有一种方法可以使用 virtualenv / virtualenvwrapper 在特定目录(即当前目录)中创建 virtualenv 文件夹,而不是默认文件夹(即,WORKON_HOME)。
相当于:
$ python -m venv env # this creates the folder `env` in the current path
Run Code Online (Sandbox Code Playgroud) 在对 JSON 数据建模时,我们通常必须处理唯一的对象标识符。我们可以将它们建模为 (i) key (或property ) 或 (ii) value。哪个是最好的解决方案,如果有的话,或者有什么优点和缺点?这里有一个例子。
标识符为键:
[
{
"1": {
"tel": "tel1",
"e-mail": "mail2"
}
},
{
"2": {
"tel": "tel2",
"e-mail": "mail2"
}
}
]
Run Code Online (Sandbox Code Playgroud)
标识符作为id键的值:
[
{
"id": 1,
"tel": "tel1",
"e-mail": "mail2"
},
{
"id": 1,
"tel": "tel2",
"e-mail": "mail2"
}
]
Run Code Online (Sandbox Code Playgroud) python ×4
virtualenv ×2
angularjs ×1
branch ×1
css ×1
django ×1
fastapi ×1
git ×1
godaddy-api ×1
javascript ×1
json ×1
leaflet ×1
lets-encrypt ×1
mongodb ×1
oop ×1
pydantic ×1
pyenv ×1
pymongo ×1
pytest ×1
traefik ×1