在我的模型中,我想使用验证器来分析文件的内容,我想不通的是如何访问文件的内容来解析它,因为文件尚未保存(这很好) 当验证器正在运行时。
我不明白如何将value
传递给验证器的数据获取到文件中(我假设我应该使用tempfile
),以便我可以打开它并评估数据。
这是一个简化的示例,在我的真实代码中,我想打开文件并使用 csv 对其进行评估。
在 Models.py 中
class ValidateFile(object):
....
def __call__(self, value):
# value is the fieldfile object but its not saved
# I believe I need to do something like:
temp_file = tempfile.TemporaryFile()
temp_file.write(value.read())
# Check the data in temp_file
....
class MyItems(models.Model):
data = models.FileField(upload_to=get_upload_path,
validators=[FileExtensionValidator(allowed_extensions=['cv']),
ValidateFile()])
Run Code Online (Sandbox Code Playgroud)
谢谢您的帮助!
从今天的阅读中,在所有示例中,我发现在与Django完全不同的容器中没有发现芹菜的任何地方。它好像芹菜有是在同一容器中,因为它走的应用程序的源文件,并查找tasks.py以及初始celery.py那是正确的还是今天的表现我误读?
例如。我熟悉使用docker-compose来启动Django,Nginx,Postgres和一个存储容器。我以为我要添加一个celery和rabbitmq容器,但是我看不到将Django配置为使用远程Celery服务器的方法。
我对Celery的了解还很早,我希望这不是我在其他地方忽略的事情。
谢谢
-p
我只是尝试使用此功能从网络获取图像
Completer<ImageInfo> completer = Completer();
Future<ui.Image> getImage(String path) async {
[var img = new NetworkImage(path);
img.resolve(ImageConfiguration()).addListener(ImageStreamListener((ImageInfo info,bool _){
completer.complete(info);
}));][1]
ImageInfo imageInfo = await completer.future;
return imageInfo.image;
}
Run Code Online (Sandbox Code Playgroud)
但我遇到了无法解决的问题。附加屏幕截图中的完整错误。
我可以使用CLI找到这种格式
aws sns publish --topic-arn arn:aws:sns:us-west-2:111111111111:test
--message "Testing the CLI"
--subject "From the CLI" --message-attributes "{\"somename\":
{\"DataType\":\"String\",\"StringValue\":\"somevalue\"}}"
Run Code Online (Sandbox Code Playgroud)
但我无法找到(或弄清楚)的是如何从API网关上的集成请求中执行此操作.
我认为它需要作为集成请求的查询参数来完成,但语法与为SQS添加消息属性不同.我通过使用此示例的参数命名符号来测试它:
MessageBody=This+is+a+test+message
MessageAttribute.1.Name=test_attribute_name_1
MessageAttribute.1.Value.StringValue=test_attribute_value_1
MessageAttribute.1.Value.DataType=String
Run Code Online (Sandbox Code Playgroud)
我也尝试过:
MessageAttributes '{"store":{"DataType":"String","StringValue":"example_corp"}}'
Run Code Online (Sandbox Code Playgroud)
到目前为止无法让它工作,任何帮助都非常感激.
@property
我的模型中有一个,它基本上是模型中几个值的字符串组合。
@property
def mfg_link(self):
return ''.join('http://mfg.com/model/' + str(self.model_numer))
Run Code Online (Sandbox Code Playgroud)
我可以将它添加mfg_link
到list_display
管理模型上并且它工作正常,但是当我将查询集传递给表时它没有显示在生成的表中,其他字段显示正常。
这似乎很明显,但不幸的是,几个小时的搜索并没有帮助。
非常感谢!
我想在我的虚拟环境中安装django-rq,但我遇到了这个错误:
pip install django-rq
Collecting rq>=0.3.4 (from django-rq)
Using cached rq-0.5.1-py2.py3-none-any.whl
Hash of the package https://pypi.python.org/packages/py2.py3/r/rq/rq-0.5.1- py2.py3-none-any.whl#md5=45418bdc995c394b4293180a4c29cb88 (from
https://pypi.python.org/simple/rq/) (e9d365b19b099235441599de78b25042) doesn't match the expected hash 45418bdc995c394b4293180a4c29cb88!
Bad md5 hash for package https://pypi.python.org/packages/py2.py3/r/rq/rq-0.5.1-py2.py3-none-any.whl#md5=45418bdc995c394b4293180a4c29cb88 (from https://pypi.python.org/simple/rq/)
Run Code Online (Sandbox Code Playgroud)
我尝试在虚拟环境之外安装它,它工作得非常好.但我不确定为什么不在虚拟环境中安装.