python - Django: 'Data' 对象没有属性 'save'

标签 python django postgresql

我正在尝试将两个 int 值保存到我的 postgreSQL 数据库中,并且即将显示以下回溯:'Data' object has no attribute '保存'。我不知道哪里出了问题。

我的模型...

from django.db import models

class Data(models.Model):
    value = models.IntegerField()
    curr_time = models.IntegerField()

我的观点...

from django.shortcuts import render,redirect
from django.views.generic import View
from django.http import JsonResponse
from models import Data

class Data(View):
    def get(self, request, date, val):
        data = Data(value=int(val), curr_time=int(date))
        data.save()
        return JsonResponse({'status': 111})

我查了查 Stack Overflow,没有找到任何答案。有人看到任何明显的错误吗?

最佳答案

您的view 类名称和model 类名称相同。将 view 类的名称更改为其他名称,即:DataView

关于python - Django: 'Data' 对象没有属性 'save',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36192061/

相关文章:

python - 元组中的总和值(字典中的值)

python - 如何在 Python 3 中获取 Unicode 代码点(如从数据库中获取)

sql - PostgreSQL:在特定数据库中创建模式

sql - PostgreSQL 错误 : subquery must return only one column

sql - 是否可以让 PostgreSQL 函数返回 “arbitrary” 类型?

python - 将列表中的每三个项目组合在一起 - Python

python - 无法导入 Boost.Python 创建的 dll(遵循 Boost Python 的 QuickStart)

JavaScript生成的Materialise卡片显示问题

django - 如何在 django 中创建这样一个带有复选框的表?

python - django 媒体的多个存储引擎 : prefer local, 回退到 CDN