【问题标题】:how to insert data to database without forms.py in django如何在没有forms.py的情况下在django中将数据插入数据库
【发布时间】:2022-07-21 16:22:00
【问题描述】:

这种方法对我来说很好用,有人可以说如何添加这样的文件或图像

def insert_students(request);
    name = request.POST['name']
    class = request.POST['class']
    student = studentsmodels(name=name, class=class)
    student.save()
    return redirect('/')
return render(request, "insertpage.html")

【问题讨论】:

    标签: django django-models django-views django-forms django-templates


    【解决方案1】:

    坦率地说,使用 Django 表单会让你的生活变得更轻松。但是,您仍然可以创建没有表单的对象并向其中添加文件。而不是request.POST,文件存储在request.FILES,文档详细介绍了文件的上传方式:

    https://docs.djangoproject.com/en/4.0/topics/http/file-uploads/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-27
      • 2019-12-11
      • 2015-02-05
      相关资源
      最近更新 更多