【发布时间】:2019-07-10 17:15:57
【问题描述】:
我正在尝试从数据库中获取一些数据以显示在视图上,但我向我显示了一个错误,我的代码甚至不存在。
我有模型 CustomCliente:
class CustomCliente(AbstractUser):
email = models.EmailField(unique=True, null=False, blank=False)
full_name = models.CharField(max_length=120, null=False, blank=False)
password = models.CharField(max_length=40, null=False, blank=False)
username = models.CharField(max_length=110, unique=True, null=False, blank=False)
我有以下方法的看法:
def mostrar_relatorio(request, id):
aluguel = Aluguel.objects.get(cliente=CustomCliente.objects.get(id=id))
if aluguel is not None :
context = {'aluguel': aluguel}
template_name = 'relatorio.html'
else:
raise Http404
return render(request, template_name, context)
我在那个模型中的 urls 模式是:
urlpatterns = [
path('cliente/<int:id>', CustomCliente, name='relatorio'),
]
当我尝试访问以下 url 127.0.0.1:8000/cliente/2 时,会发生错误: 'CustomCliente' 对象没有属性 'get.即使我的代码中没有任何地方调用 CustomCliente.get。 我已经尝试关闭服务器并再次尝试,重写代码,但它似乎不起作用。
【问题讨论】:
标签: django django-models django-views django-users