【发布时间】:2015-04-23 00:58:35
【问题描述】:
我遇到了一个错误,我真的不知道为什么 Django 会做出奇怪的反应。
如果我写:
from jezyk.models import Jezyk
from pytania.models import Pytanie
from userprofile.models import UserProfile
def test_qr(request):
# Create the HttpResponse object with the appropriate PDF headers.
response = HttpResponse(content_type='application/pdf')
response['Content-Disposition'] = 'attachment; filename="egzamin.pdf"'
uzyt = UserProfile.objects.all().order_by('user_id')
jez = Jezyk.objects.all()
pytanie = Pytanie.objects.all().order_by('godzina')
p = canvas.Canvas(response)
for z, uzyt in enumerate(UserProfile.objects.order_by('godzina', 'jezyk_id')):
if jez.jezyk == 'EN' :
for i, pytanie in enumerate(Pytanie.objects.all()):
p.drawString(10, 400 + i*210, ' '+ pytanie.title)
我收到一个错误:
Exception Value: 'QuerySet' object has no attribute 'jezyk'
这个错误来自这里:
if jez.jezyk == 'EN' :
我觉得很奇怪,因为这段代码有效:
uzyt = UserProfile.objects.all().order_by('user_id')
为什么无法从表 jezyk 访问列 jezyk?
在我的 sqlite 表 jezyk 中,我有 2 列:id 和 jezyk,如下所示:
【问题讨论】:
-
如果清楚代码的用途会有所帮助。
标签: python django python-2.7 django-views