如果键是电子邮件 ID,如何从 yaml 文件中读取键值对?

时间:2021-02-03 16:48:56

标签: yaml yq

Yaml 文件名:abc.yaml

abc.yaml 内容

from .choices import price_choices, bedroom_choices, area_choices
    def search(request):
        queryset_list = Oglas.objects.order_by('-list_date')
    
        # keywords
        if 'keywords' in request.GET:
            keywords = request.GET['keywords']
            if keywords:
                queryset_list = queryset_list.filter(description__icontains = keywords)  
        # Area
        if 'area' in request.GET:
            area = request.GET['area']
            if area:
                queryset_list = queryset_list.filter(area__iexact = area)
        # rooms 
        if 'bedrooms' in request.GET:
            bedrooms = request.GET['bedrooms']
            if bedrooms:
                queryset_list = queryset_list.filter(bedrooms__lte=bedrooms) 
    
        # price
        if 'price' in request.GET:
            price = request.GET['price']
            if price:
                queryset_list = queryset_list.filter(price__lte = price)
        
        context = {
            'area_choices' : area_choices,
            'bedroom_choices' : bedroom_choices,
            'price_choices' : price_choices,
            'listings' : queryset_list,
            'values' : request.GET,
        }   
        return render(request, 'pages/search.html', context)

我试过 abc@in.xyz.com: 12345 xyz@in.xxx.com: 23456 输出为空。

1 个答案:

答案 0 :(得分:1)

在 mikefarah/yq 3.x 下,要访问 path names with special characters,你用 " 引用它们,所以它会

yq read abc.yaml '"abc@in.xyz.com"'

如果您在生产或构建管道中使用 v3.x,您应该知道作者不再支持它,并且应该考虑升级到 v4.x,因为它支持更多功能。查看关于 Upgrading from V3

的注释

在最新版本 yq version 4.4.1 上,您可以这样做

yq e '."abc@in.xyz.com"' abc.yaml