小编Jad*_*ade的帖子

'unicode'对象没有属性'get'

我正在写django应用程序并坚持错误

'unicode' object has no attribute 'get'
Run Code Online (Sandbox Code Playgroud)

我在这看到很多问题,但没有人跟我的问题相符.

问题是我在views.py中的方法应该返回JSON:

def get_pattern(request, product_id):
    """
    Get JSON for needed pattern
    """
    data = Patterns.objects.get(related_module=product_id)
    product_data = serializers.serialize("json", [data, ])
    return product_data
Run Code Online (Sandbox Code Playgroud)

我的urls.py

urlpatterns = [
url(r'^get_pattern(?P<product_id>[0-9]+)/$', views.get_pattern, name='get_pattern'),
Run Code Online (Sandbox Code Playgroud)

]

我已经尝试了一切.但当你去/ get_pattern1它返回:

Request Method: GET
Request URL:    http://xxxxxxx:8000/xxxx/get_pattern1/
Django Version: 1.8.3
Exception Type: AttributeError
Exception Value:    
'unicode' object has no attribute 'get'
Exception Location: /home/xxxx/local/lib/python2.7/site-    packages/django/middleware/clickjacking.py in process_response, line 31
Run Code Online (Sandbox Code Playgroud)

python django unicode django-orm attributeerror

5
推荐指数
1
解决办法
2万
查看次数

Get-Content的PowerShell问题

我有一个问题.当我运行命令时:

powershell -command"gc C:\ Program Files\Microsoft SQLServer\MSSQL.1\MSSQL\LOG\ERRORLOG -totalcount 5

有一个错误:

"Get-Content:找不到接受参数'Files\Microsoft'的位置参数.在行:1 char:3 + gc <<<< C:\ Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOG\ERRORLOG -to talcount 5 + CategoryInfo:InvalidArgument :( :) [Get-Content],ParameterBindingException + FullyQualifiedErrorId:PositionalParameterNotFound,Microsoft.PowerShell.Commands.GetContentCommand"

你能帮帮我吗?

windows powershell remote-access file-get-contents windows-console

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

如何在不包含枚举变体名称的情况下序列化枚举?

我试图将枚举序列化为JSON字符串.我Serialize为我的枚举实现了特征,因为它在文档中有描述,但我总是得到{"offset":{"Int":0}}而不是想要的{"offset":0}.

extern crate serde;
extern crate serde_json;

use std::collections::HashMap;

use serde::ser::{Serialize, Serializer};

#[derive(Debug)]
enum TValue<'a> {
    String(&'a str),
    Int(&'a i32),
}

impl<'a> Serialize for TValue<'a> {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: Serializer,
    {
        match *self {
            TValue::String(ref s) => serializer.serialize_newtype_variant("TValue", 0, "String", s),
            TValue::Int(i) => serializer.serialize_newtype_variant("TValue", 1, "Int", &i),
        }
    }
}

fn main() {
    let offset: i32 = 0;
    let mut request_body = HashMap::new();
    request_body.insert("offset", TValue::Int(&offset));
    let serialized = …
Run Code Online (Sandbox Code Playgroud)

serialization rust serde serde-json

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

如何在Windows cmd中打印文件的前5行

如何在Windows CMD中打印文件的前5行?

有一个问题我无法使用PowerShell(特定任务)和批处理脚本.你能帮帮我吗?

windows grep head windows-console

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