“ DeferredAttribute”对象不可调用

时间:2019-08-31 11:15:24

标签: django

我正在做一个简单的django项目,但是我遇到了您在下面看到的这个问题,因此,我想要一个解决方案,因为我真的很累

我希望该代码的输出为numberone,但实际输出为该错误:

TypeError at /db/
'DeferredAttribute' object is not callable
Request Method: GET
Request URL:    http://127.0.0.1:8000/db/
Django Version: 2.1.5
Exception Type: TypeError
Exception Value:    
'DeferredAttribute' object is not callable
Exception Location: /home/mohammed/Desktop/New life programming/python     /pythonDjano/Filecorse/NewDjango/MohammedAlaa/Abdullah/views.py in db, line     16
Python Executable:  /usr/bin/python3
Python Version: 3.6.8
Python Path:    
['/home/mohammed/Desktop/New life '
 'programming/python/pythonDjano/Filecorse/NewDjango/MohammedAlaa',
 '/usr/local/lib/python3.6/dist-packages/pip-19.1.1-py3.6.egg',
 '/usr/lib/python36.zip',
 '/usr/lib/python3.6',
 '/usr/lib/python3.6/lib-dynload',
 '/home/mohammed/.local/lib/python3.6/site-packages',
 '/usr/local/lib/python3.6/dist-packages',
 '/usr/lib/python3/dist-packages']
 Server time:   Sat, 31 Aug 2019 11:13:18 +0000

views.py

from django.shortcuts import render
from django.http import HttpResponse
from .models import Product
def Home(request):
    return HttpResponse('Welcome, Mohammed Alaa :)')
def htm(request):
    return render(request,'htm.html',{'hello':"hello Mohammed Abo Alaa again:)",                             'days':['wed', 'fri', 'thru']
        })
def others(request):
    return HttpResponse('Welcome, Mohammed Alaa :) form others')

def db(request):
    dat = ''
    p1 = Product(namee='numberone', pricee=500,Type='m')
    p1.save()
    dat = Product.namee()
    return HttpResponse(dat)

1 个答案:

答案 0 :(得分:0)

您需要引用刚创建的Product实例,而不是整个Product类。而且它只是一个字符串,不需要调用它。

$(CXX)