【问题标题】:ValueError: invalid literal for int() errorValueError:int() 错误的无效文字
【发布时间】:2015-12-12 13:47:29
【问题描述】:

您好,我正在为我的网站使用 Django 框架。我有一个项目中的视图,它将数据保存到数据库(模型)中。但是当我运行我的程序时,出现如下错误

ValueError: invalid literal for int() with base 10: '2015-08-24 12:27:58'

我的意见.py

class ProcessCheckBinningView(JSONResponseMixin, View):
    #model = OrcAwaiverBin
    def post(self, request, *args, **kwargs):

        status = 'error'
        msg = "this is from me"

        post_body = json.loads(self.request.body)
        fab_value = post_body['fab']
        technode_value = post_body['technode']
        layer_value = post_body['layer']

        print fab_value, technode_value, layer_value
        print "submitted from the template f"
        bin_object = OrcAwaiverBin()
        # Record the last accessed date
        bin_object.fab = fab_value
        bin_object.technology = technode_value
        bin_object.layer = layer_value
        print "OKKKKK"
        bin_object.created_by = '2015-08-24 12:27:58'
        bin_object.date_modified = '2015-08-24 12:27:58'
        bin_object.save()
        return self.render_json_response(dict(status=status, msg=msg))

class CheckBinningView(TemplateView):
    template_name = "orc_enable.html"

    def get_context_data(self, *args, **kwargs):
        context = super(CheckBinningView, self).get_context_data(*args, **kwargs)
        fab = GroupProfile.objects.get(id=self.request.session['ACL_gid']).fab
        gp = GroupProfile.objects.get(id=self.request.session['ACL_gid'])
        context['fab'] = gp.fab
        context['ngapp'] = "CMOD"
        return context

我的模型字段:

date_created = models.DateTimeField(auto_now_add=True)
date_modified = models.DateTimeField(blank=True)

谁能告诉我这里有什么问题?提前致谢。

【问题讨论】:

  • OrcAwaiverBin模型粘贴models.py的代码
  • 更新了我的模型字段
  • @gentle 请发布完整的堆栈跟踪!此外,您确定self.request.session['ACL_gid'] 是整数,因为您正试图通过id 获取GroupProfile 对象?

标签: python django django-models django-views


【解决方案1】:

根据错误提示,您应该将bin_object.created_by 字段或bin_object.date_modified 字段声明为IntegerField

【讨论】:

  • 没有它的日期时间字段。也用模型更新了我的问题
【解决方案2】:

问题是,正如 Aswin 所说,我的模型只接受整数值。我试图插入日期时间值。谢谢各位!

【讨论】:

    猜你喜欢
    • 2018-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-09
    • 2016-11-14
    • 1970-01-01
    • 2021-01-07
    相关资源
    最近更新 更多