Python 如何使用django表单将数据插入数据库?
我试图使用django表单向数据库中插入一些信息,但插入现在工作正常 这是我正在使用的带有一些输入的表单页面Python 如何使用django表单将数据插入数据库?,python,jquery,django,django-forms,qr-code,Python,Jquery,Django,Django Forms,Qr Code,我试图使用django表单向数据库中插入一些信息,但插入现在工作正常 这是我正在使用的带有一些输入的表单页面 <!DOCTYPE html> <html lang="en"> <head> <!-- /Css --> <link rel = "stylesheet" type = "text/css" href = "../static/survey.css" /> <!-- /Css --> <meta
<!DOCTYPE html> <html lang="en">
<head>
<!-- /Css -->
<link rel = "stylesheet" type = "text/css" href = "../static/survey.css" />
<!-- /Css -->
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Preencha a pesquisa de satisfação</title>
<style>
* {
box-sizing: border-box;
}
input[type=submit] {
background-color: #4CAF50;
color: white;
padding: 10px 10px;
border: none;
border-radius: 4px;
cursor: pointer;
float: right;
}
input[type=submit]:hover {
background-color: #45a049;
}
.col-25 {
float: left;
width: 50%;
margin-top: 6px;
}
.col-75 {
float: left;
width: 100%;
margin-top: 5px;
}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
</style>
<!-- /Fonts -->
<link href='https://fonts.googleapis.com/css?family=Comfortaa' rel='stylesheet'> <link href="https://fonts.googleapis.com/css?family=Poppins:100,100i,200,200i,300,300i,400,400i,500,500i,600,600i,700,700i,800,800i,900" rel="stylesheet">
<!-- /Fonts -->
</head>
<body>
<h2>Pesquisa de satisfação</h2>
<p>Avalie a sua experiência em nosso restaurante e nos ajude a melhor o atendimento.</p>
<div class="container">
<h2>{{ note }}</h2>
<form class="formSurvey" action="{% url 'servicesurvey' %}" method="post">
{% csrf_token %}
{{ surveyform }}
<div class="row">
<input type="submit" value="Submit">
</div>
</form>
</div>
<div>
<a href="{% url 'home' %}">Voltar</a>
</div>
</body> </html>
models.py,其中包含我试图保存在数据库中的2个输入
from django.db import models
class Survey(models.Model):
aboutTheService = models.CharField(max_length=100)
aboutTheFood = models.CharField(max_length=100)
您应该在块中使用
filled\u form.save()
if filled\u form.is\u valid():您可以显示SurveyForm的代码吗?
?请修复代码段的缩进,因为现在完全不清楚什么属于哪里。但是是的,正如@PRMoureu所说,如果你不save()
任何东西,都不会被保存。谢谢Daniel Roseman!它起作用了!!
from django.db import models
class Survey(models.Model):
aboutTheService = models.CharField(max_length=100)
aboutTheFood = models.CharField(max_length=100)