Django对象没有属性状态\ U代码

2024-09-29 00:18:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在学习开发并尝试在Django1.1中开发一个屏幕,我在下面看到了这个错误。我已经查看了一些堆栈,我已经查看了httpresponse,但是,我没有成功 有人能帮我解释一下可能出了什么问题吗

我在控制台上遇到以下错误:

Internal Server Error: /gerencia-margem/list
Traceback (most recent call last):
File "/home/murilo/virtualenv/intranet_erp/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 131, in get_response
response = middleware_method(request, response)
File "/home/murilo/virtualenv/intranet_erp/local/lib/python2.7/site-packages/django/middleware/locale.py", line 38, in process_response
if (response.status_code == 404 and not language_from_path and
AttributeError: 'HistoricoComissao' object has no attribute 'status_code'
[18/Nov/2020 13:30:06] "GET /gerencia-margem/list HTTP/1.1" 500 77145

这是模型,

# -*- coding: utf-8 -*-
from django.db import models


class HistoricoComissao(models.Model):
class Meta:
    verbose_name = u'Historico Comissão'
    verbose_name_plural = u'Historico Comissões'

pednum = models.CharField(max_length=40, blank=True)
margem = models.DecimalField(decimal_places=4, max_digits=15, null=True, blank=True) 
data = models.DateTimeField()
historico = models.TextField((u'Historico HTML'), blank=True)

status = models.PositiveSmallIntegerField(choices=[(1, 'Em Aberto'),
                                                   (3, 'Pendente'),
                                                   (4, 'Finalizado'),])

def __unicode__(self):
        return str(self.pednum)

这就是我们的观点

from django.views import View
from django.shortcuts import render
from django.http import HttpResponseRedirect, HttpResponse
from django.core.urlresolvers import reverse
from ..models import HistoricoComissao


def listview(request):
template_name = 'comissao/margenslist.html'
comissoes = HistoricoComissao.objects.all
context = {
    'comissoes': comissoes
}
return render(request,template_name,context)

这是url.py

from django.conf.urls import  url
from . import views


urlpatterns = [
    url(r'^list$', views.HistoricoComissao, name='historico_comissao'),
 ]

Tags: djangonamefrompyimporttruemodelsresponse
1条回答
网友
1楼 · 发布于 2024-09-29 00:18:56

urls.py中,您使用as view HistoricoComissao,但这是Django模型的再导出,而不是视图的再导出。您应该使用listview

from django.conf.urls import  url
from . import views


urlpatterns = [
    # link to a view function ↓
    url(r'^list$', views.listview, name='historico_comissao'),
]

I am learning to develop and trying to develop a screen in django 1.1.

请升级。Django-1.1在2013年之前就已经报废了。此外,在此期间,很多事情都发生了变化(并且经常有所改善)

相关问题 更多 >