我正在尝试将两个 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/