使用Django信号receiver装饰器我有以下功能.
@receiver(post_save)
def action_signal(sender, instance, created, **kwargs):
pass
Run Code Online (Sandbox Code Playgroud)
是否可以receiver在类上使用装饰器而不是函数?原因是我想要一个__init__方法等.
即我怎样才能得到这样的东西......
class ActionSignals
def __init__(self):
self.stuff
@receiver(post_save)
def action_signal(sender, instance, created, **kwargs):
print(self.stuff)
Run Code Online (Sandbox Code Playgroud) 如何确保使用pip安装的软件包不安装已安装的依赖项apt-get?
例如,在Ubuntu上,您可以使用Numpy安装包apt-get install python-numpy.哪个安装到:
usr/local/lib/python2.7/dist-packages
Run Code Online (Sandbox Code Playgroud)
我注意到,当我安装一个需要使用numpy的软件包时,它不再跳过numpy依赖pip,pip install scipy而是再次安装到另一个位置.
/usr/lib/python2.7/dist-packages
Run Code Online (Sandbox Code Playgroud)
pip应该做的是跳过全局安装的任何python包,对吧?
deconstructiblePython 中的装饰器有什么作用?我遇到了这个装饰器,正在查看其他人的代码,但是我搜索了Python文档,却找不到该装饰器的实际功能?
@deconstructible
class UserValidator(object):
def __call__(self, value):
if value:
etc
Run Code Online (Sandbox Code Playgroud)
给定上面的代码,对此类添加'deconstructible'有什么作用?
使用Django 1.9 和 Python 3.4,我想复制现有模型实例及其所有相关数据。以下是我目前如何实现这一目标的示例。我的问题是,有没有更好的方法?
我已经阅读了一些帖子,例如在 Django / Algorithm 中复制模型实例及其相关对象,用于重复复制一个对象,但是,它们已经超过 8 年了,不再与 Django 1.9+ 一起使用。
下面是我如何尝试在 Django 1.9 中实现这一点,好的还是更好的方法?
楷模
class Book(models.Model):
name = models.CharField(max_length=80)
class Contributor(models.Model):
name = models.CharField(max_length=80)
books = models.ForeignKey("Book", related_name="contributors")
Run Code Online (Sandbox Code Playgroud)
复制功能。我必须在保存新的 Book 实例后重新创建贡献者,否则,它将从我正在复制的实例中分配现有的贡献者。
def copy_book(self, id):
view = self.context['view']
book_id = id
book = Book.objects.get(pk=book_id)
copy_book_contributors = book.contributors.all()
book.id = None
# make a copy of the contributors items.
book.save()
for item in copy_book_contributors:
# We need to copy/save the …Run Code Online (Sandbox Code Playgroud) 在 Auth.signIn() 之后调用 Auth.currentUserCredentials() 时,我获得了有效的有效凭据,但对于未经身份验证的用户,为什么?
代码:
async signIn({ dispatch, state }, { email, password }) {
try {
const user = await Auth.signIn(email, password);
console.log("User state after login")
const userCredentialsAfterLogin = await Auth.currentUserCredentials();
console.log(userCredentialsAfterLogin)
} catch (error) {
console.log("error")
console.log(error)
return
}
await dispatch('fetchUser')
},
Run Code Online (Sandbox Code Playgroud)
预期行为:
使用有效用户登录后,Auth.currentUserCredentials() 应返回一组经过身份验证的凭据。
实际行为:
Auth.currentUserCredentials() 返回未经身份验证的用户,其经过身份验证的属性设置为false和 400 错误,“ ResourceNotFoundException: IdentityPool 'eu-west-1:62dab5ed-5a84-4064-a7a2-87d1d0df511b '
系统:
配置
{
"authSelections": "userPoolOnly",
"resourceName": "testapp89e81d50",
"serviceType": "imported",
"region": "eu-west-1"
}
Run Code Online (Sandbox Code Playgroud) 我目前正在supervisor为我的 Django 应用程序提供服务,然后我将其expose移植8002到我的 Docker 文件中。这一切正常...
[program:app]
command=gunicorn app.core.wsgi:application -c /var/projects/app/server/gunicorn.conf
user=webapp
backlog = 2048
chdir = "/var/projects/apps"
bind = "0.0.0.0:8002"
pidfile = "/var/run/webapp/gunicorn.pid"
daemon = False
debug = False
Run Code Online (Sandbox Code Playgroud)
在 Docker 中
# Expose listen ports
EXPOSE 8002
Run Code Online (Sandbox Code Playgroud)
但是,有人告诉我最好使用 socket在端口,但是我不确定如何在我的 Docker 文件中“暴露”一个套接字。这是我有多远:
新的主管配置....
backlog = 2048
chdir = "/var/projects/apps"
bind = "unix:/var/run/webapp/gunicorn.sock"
pidfile = "/var/run/webapp/gunicorn.pid"
daemon = False
debug = False
Run Code Online (Sandbox Code Playgroud)
码头工人
# Expose listen ports
EXPOSE ???? (may be unix:/var/run/webapp/gunicorn.sock fail_timeout=0;???)
Run Code Online (Sandbox Code Playgroud)
我如何暴露套接字?
在 vue.js 中。我有以下 auth.js,在 js 文件的底部有“导出默认值”。在我的 Registration.vue 文件中如何访问“操作”?
这是我尝试过的:
注册.vue
import {actions} from 'src/util/auth';
export default {
components: {
actions
},
data(){
},
methods: {
submitReg() {
console.log(actions)
}
}
}
Run Code Online (Sandbox Code Playgroud)
错误:在“src/util/auth”中找不到导出“actions”
这是 auth.js 文件完整代码,此处https://gist.github.com/toricls/5c38d2930a36262f0674c1ffa8d5134a:
import Amplify, { Auth } from 'aws-amplify';
const state = {
user: null,
};
const actions = {
async getCurrentUserInfo({ commit }) {
// This is returning null - why?
// const user = await Auth.currentUserInfo();
const user = await Auth.currentAuthenticatedUser();
const attributes …Run Code Online (Sandbox Code Playgroud) 检查以下所有值的最佳方法是不是None.这是我尝试过的:
user = url_string.get('user', None)
subject = url_string.get('subject', None)
email = url_string.get('email', None)
from_address = url_string.get('from_address', None)
if not any(user, subject, email,from_address):
raise Exception('missing data')
Run Code Online (Sandbox Code Playgroud) 我正在尝试读取/访问我的 vuex 存储,但收到错误“无法读取未定义的属性 '$store',为什么?
这是我尝试过的...
我在单独的 store.js 文件中创建了一个 Vuex 商店。
import Vuex from "vuex";
import Vue from "vue";
import { Auth } from "aws-amplify";
Vue.use(Vuex);
export const store = new Vuex.Store({
state: {
user: null
},
actions: {
// AWS signup action.
async signUp({ commit }, { username, password, firstName, lastName }) {
const data = await Auth.signUp({
username,
password,
attributes: {
given_name: firstName,
family_name: lastName
}
});
console.log(data);
}
}
});
Run Code Online (Sandbox Code Playgroud)
接下来,我将其注册到我的main.js Vue 实例中。
import Vuex from 'vuex' …Run Code Online (Sandbox Code Playgroud) 我正在使用 terraform v1.1.3,每当我运行terraform plan它时,它都会声明我已进行更改,即使本地或远程没有任何更改。例如,如果我立即运行terraform applythen terraform plan,它会声明对象已在 Terraform 之外发生更改,并强制替换我的实例。
# module.database.oci_core_instance.instance[0] has changed
~ resource "oci_core_instance" "minstance" {
+ extended_metadata = {}
id = "ocid1.instance.oc1.me-jeddah-1.anvgkljrnghkmsacizo3ubuejydotfi7qz45if32x2e3b55mhirvrvpiw7nq"
Run Code Online (Sandbox Code Playgroud)
为什么?
resource "oci_core_instance" "instance" {
availability_domain = random_shuffle.compute_ad.result[count.index % length(random_shuffle.compute_ad.result)]
compartment_id = var.compartment_id
shape = var.instance_shape
freeform_tags = var.freeform_tags
shape_config {
memory_in_gbs = 16
ocpus = 1
}
source_details {
source_type = "image"
source_id = lookup(data.oci_core_images.compute_images.images[0], "id")
}
metadata = {
ssh_authorized_keys = file(var.ssh_public_key)
user_data = data.template_cloudinit_config.nodes.rendered
}
count = …Run Code Online (Sandbox Code Playgroud) python ×6
django ×4
python-3.x ×3
vue.js ×3
apt-get ×1
aws-amplify ×1
debian ×1
docker ×1
ecmascript-6 ×1
es6-modules ×1
javascript ×1
pip ×1
terraform ×1
ubuntu ×1
vuejs2 ×1
vuex ×1