小编Man*_*pta的帖子

Postgresql 错误:必须出现在 GROUP BY 子句中或在聚合函数中使用

在你把它标记为重复之前,我尝试了同一个网站上给出的几种解决方案,但没有一个有效。

我的查询

SELECT 
  temp_fk_settlements.sku, 
  temp_fk_settlements.order_item_id, 
  temp_fk_settlements.order_date, 
  sum(temp_fk_settlements.order_item_value), 
  sum(temp_fk_settlements.total_marketplace_fee), 
  sum(temp_fk_settlements.service_tax), 
  sum(temp_fk_settlements.settlement_value), 
  sum(temp_fk_settlements.commission), 
  sum(temp_fk_settlements.fixed_fee), 
  sum(temp_fk_settlements.shipping_fee), 
  sum(temp_fk_settlements.reverse_shipping_fee), 
  sum(temp_fk_settlements.invoice_amount)
FROM 
  temp_fk_returns, 
  temp_fk_settlements
WHERE
  temp_fk_settlements.order_item_id = temp_fk_returns.order_item_id and
  temp_fk_returns.return_type = 'customer_return'
GROUP BY
  temp_fk_settlements.order_item_id
Run Code Online (Sandbox Code Playgroud)

我的错误

ERROR:  column "temp_fk_settlements.sku" must appear in the GROUP BY clause or     
 be used in an aggregate function
LINE 2:   temp_fk_settlements.sku, 
Run Code Online (Sandbox Code Playgroud)

如果我尝试删除列 temp_fk_settlements.sku 它仍然在不同的列上给我错误。我被卡住了,因为没有一个解决方案有效。

我想根据 order_item_id 对结果进行分组。

我的表结构是

temp_fk_settlements:

Create table temp_fk_settlements(
    settlement_reference_no varchar(50),
    order_type char(20),
    fulfillment_type varchar(25),
    sku varchar(25),
    order_id varchar(25),
    order_item_id varchar(25),
    order_date date,
    dispatch_date date,
    delivery_date date,
    cancellation_date …
Run Code Online (Sandbox Code Playgroud)

sql postgresql

1
推荐指数
1
解决办法
9966
查看次数

TypeError:必须可以转换为缓冲区,而不是HTTPResponse

我有一个从api连接获取pdf文件的函数.

我的代码:

label = fk.fetch_labels(oiids)
with open('a.pdf', 'wb') as handle:
    cont = label.raw
    print cont
    handle.write(cont)`
Run Code Online (Sandbox Code Playgroud)

fetch_labels:

def fetch_labels(self, orderItemIds):
    headers = {'Accept': 'application/octet-stream'}
    url = "https://api.flipkart.net/sellers/orders/shipments"
    payload = {'orderItemIds':','.join(orderItemIds)}
    return self.session.get(url, headers=headers, params=payload, stream=True)`
Run Code Online (Sandbox Code Playgroud)

在运行上面的代码它会抛出错误:

<urllib3.response.HTTPResponse object at 0x7f1d8fa24d50>
Traceback (most recent call last):
  File "test.py", line 23, in <module>
    handle.write(cont)
Run Code Online (Sandbox Code Playgroud)

TypeError:必须可以转换为缓冲区,而不是HTTPResponse`

当我使用'wb'将其写入pdf文件时,它只是创建一个0字节的文件.什么是正确的方式.

python python-requests

1
推荐指数
1
解决办法
8444
查看次数

python请求错误422

我正在尝试通过 rest api 发布请求结构。

我的代码:

def pack_orders(self, orderItemId, invoiceDate, invoiceNumber, tax, serialNumbers=None, subOrderItemId = None, subSerialNumbers = None, subInvoiceDate = None, subTax = None):
    url = "https://api.flipkart.net/sellers/orders/labels"
    payload = {[{"orderItemId": orderItemId,
                "serialNumbers": serialNumbers,
                "invoiceDate": invoiceDate,
                "invoiceNumber": invoiceNumber,
                "tax": tax,
                "subItems": [{
                    "orderItemId": subOrderItemId,
                    "serialNumbers": subSerialNumbers,
                    "invoiceDate": subInvoiceDate,
                    "tax": subTax}]
                }],}
    return self.session.post(url, params=payload)
Run Code Online (Sandbox Code Playgroud)

调用上面的函数:

label = fk.pack_orders(orderItemId='232519872', invoiceDate='2015-08-13',       invoiceNumber='INVSTR01', tax=5)
print label.status_code
print label.url
print label.content
Run Code Online (Sandbox Code Playgroud)

它抛出错误 422。我知道它必须对请求参数结构做一些事情。我无法查明错误的来源。

这是任何帮助的文档链接。 文档

python python-requests

1
推荐指数
1
解决办法
5283
查看次数

传递单个值而不是列表django

在django list_of_ids = request.POST.getlist('field_name')中,用于获取所有html字段中的值,其中name field_name返回列表类型对象,即使只有一个字段存在该名称field_name.

因此,如果只有一个字段与给定的字段名称存在,如何将其作为char或int类型的单个对象而不是list_type传递?

例如

<form action="{% url 'pack' %}">
    <button type="submit">
    <input type="text" name="tid">
</form>
Run Code Online (Sandbox Code Playgroud)

在django views.py文件中:

def method_name(request):
    if request.method == 'POST':
        list_of_ids = request.POST.getlist('field_name')
Run Code Online (Sandbox Code Playgroud)

我想要的是什么

list_of_ids = request.POST.getobject('field_name')
Run Code Online (Sandbox Code Playgroud)

怎么做?

html python django

1
推荐指数
1
解决办法
73
查看次数

如何将字符串映射到结构体?

我有一些结构,例如:

pub struct A {}

pub struct B {}
Run Code Online (Sandbox Code Playgroud)

我想将这些结构映射到字符串映射:

let s = match x {
    "a" => A {},
    "b" => B {},
    _ => panic!()
} 
Run Code Online (Sandbox Code Playgroud)

就像 Python 字典一样。我怎样才能在 Rust 中做到这一点?

rust

1
推荐指数
1
解决办法
1339
查看次数

django数据不会动态变化

我写了一个django应用程序来显示从html模板中的mongodb获取的一些数据.所有订单商品ID都带有状态'APPROVED'

models.py:

from pymongo import MongoClient

class GetNewOrders(object):
    def __init__(self):
        self.client = MongoClient('localhost',27017)
        self.db = self.client['Flipkart']
        self.sale_order = list(self.db['sale_order'].find({'status':'APPROVED'}))

    def getOrderItemId(self):
        oiids = []
        for each in self.sale_order:
            oiids.append(each['orderItemId'])
        return oiids
Run Code Online (Sandbox Code Playgroud)

views.py:

from django.shortcuts import render
from django.http import HttpResponse
from orders.models import GetNewOrders

no = GetNewOrders()
oiids_new = no.getOrderItemId()

def orders(request):
    context_dict = {'oiids_new':oiids_new}
    return render(request, 'orders/orders.html', context_dict)
Run Code Online (Sandbox Code Playgroud)

我在我的html文件中使用了for循环来显示该数据.如果我将文档的状态更改为'APPROVED',则在我重新启动服务器之前,它不会反映在我的html中.如何在不重启django服务器的情况下在html中显示已更改的数据?

python django mongodb

0
推荐指数
1
解决办法
39
查看次数

django POST返回内部服务器500错误

我正在尝试将请求发送到django视图,但它一直在返回INTERNAL SERVER ERROR 500.

我的ajax帖子:

$.ajax({
    url : "/loginAction/",
    type : "POST",
    async : false,
    data : {action:'loginAction',
            email:email,
            password:password},

    success : function(response) {
        $.niftyNoty({
            type:"success",icon:"",title:"Login Successful. Redirecting....",container:"floating",timer:5000
        });
    },

    error : function(xhr,errmsg,err) {
        console.log(xhr.status + ": " + xhr.responseText);
        $.niftyNoty({
            type:"danger",icon:"",title:"Wrong Email OR Password",container:"floating",timer:5000
        });
    }
});
Run Code Online (Sandbox Code Playgroud)

我的django观点:

def loginAction(request):
    print "Its workjing"
    if request.method == 'POST' and 'loginButton' in request.POST:
        email = request.POST.get('email')
        password = request.POST.get('password')

        print email, password

        return HttpResponse(json.dumps({}),content_type="application/json")
Run Code Online (Sandbox Code Playgroud)

我的urls.py

urlpatterns = [
            url(r'^', …
Run Code Online (Sandbox Code Playgroud)

python django ajax

0
推荐指数
1
解决办法
8458
查看次数

标签 统计

python ×5

django ×3

python-requests ×2

ajax ×1

html ×1

mongodb ×1

postgresql ×1

rust ×1

sql ×1