Python ';unicode';对象没有属性';获取';

Python ';unicode';对象没有属性';获取';,python,django,unicode,django-orm,attributeerror,Python,Django,Unicode,Django Orm,Attributeerror,我正在编写django应用程序,遇到了错误 'unicode' object has no attribute 'get' 我在这里看到了很多问题,但没有人与我的问题相匹配 问题在于views.py中我的方法应该返回JSON: def get_pattern(request, product_id): """ Get JSON for needed pattern """ data = Patterns.objects.get(related_module=pr

我正在编写django应用程序,遇到了错误

'unicode' object has no attribute 'get'
我在这里看到了很多问题,但没有人与我的问题相匹配

问题在于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
我的URL.py

urlpatterns = [
url(r'^get_pattern(?P<product_id>[0-9]+)/$', views.get_pattern, name='get_pattern'),
Django视图必须返回对象,而不是字符串

bytes = product_data.encode('utf-8')
return django.http.HttpResponse(bytes, content_type='application/json')

(clickjacking中间件引发了一个错误,因为它假设来自视图的返回值是HttpResponse,并在其上调用
get()
,但实际上它是一个错误的
unicode
字符串。)

您有中间件吗?如果你这样做了,显示itI am猜测
模式.objects.get
实际上不是你的问题所在(假设你实际上有一个模式模型类,并且没有对那里的objects属性做一些有趣的事情)。。。您是否在控制台中看到任何错误消息(如果您使用apache托管,则在apache日志中看到)不,我没有。这几乎是原始的django安装。您是否已将debug设置为true?\@JoranBeasley当我试图通过浏览器访问它时,它会向前端和attributeError返回500个错误
return product_data
bytes = product_data.encode('utf-8')
return django.http.HttpResponse(bytes, content_type='application/json')