开发了一种具有在本地服务器上工作的模块(任务)的API。由于我将其部署在具有相同数据库和记录的Heroku上,因此可以通过bash进行访问,但是无法通过API端点对数据库模型(任务)执行任何CRUD操作。>
(任务)是指应用程序/模块目录
(任务)是指模型
models.py
class Task(models.Model):
title = models.CharField(max_length=64)
check = models.BooleanField(default=False)
date_to_do = models.DateField(default='2019-05-26', null=True, blank=True)
timestamp = models.DateTimeField(auto_now=True, null=True, blank=True)
views.py
def post(self, request, *args, **kwargs):
data = request.body
valid_json = is_json(data)
if not valid_json:
json_data = json.dumps({'msg': 'Invalid JSON data'})
return HttpResponse(json_data, content_type='application/json', status=400)
task = json.loads(data)
form = TaskForm(task)
if form.is_valid():
form.save(commit=True)
json_data = json.dumps({'msg': 'Saved Successfully'})
return HttpResponse(json_data, content_type='application/json', status=200)
if form.errors:
json_data = json.dumps(form.errors)
return HttpResponse(json_data, content_type='application/json', status=400)
Heroku日志错误
ProgrammingError at /admin/task/task/add/
relation "task_task" does not exist at LINE 1:
INSERT INTO "task_task" ("title", "check", "date_to_do", "ti...
^