我正在编写 Django 应用程序,卡在了错误上。
我看到了很多问题,但没有一个与我的问题相匹配。
我的问题是在views.py中的方法应该返回JSON:
我的urls.py
我已经尝试了所有的方法。但是当你执行 /get_pattern1 时,它返回:
'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
我的urls.py
urlpatterns = [
url(r'^get_pattern(?P<product_id>[0-9]+)/$', views.get_pattern, name='get_pattern'),
我已经尝试了所有的方法。但是当你执行 /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
Patterns.objects.get
并不是你的问题所在(假设你确实有一个 Patterns 模型类,并且没有对 objects 属性进行任何有趣的操作)... 你在控制台上看到任何错误消息了吗(如果你正在使用 Apache 进行主机托管,则可以查看 Apache 日志)? - Joran Beasleyprocess_response
的方法,请在内部查看。 - Gocht