我已经阅读了有关https://github.com/Atrox/sweetify-django的文档,但是我不清楚,我已经在Django中下载并导入了sweetify的要求。我只希望如果记录已更新,将显示弹出消息(sweetify)。
def studentrecords(request):
if request.method == 'POST':
id = request.POST.get("id")
update = StudentsEnrollmentRecord.objects.get(id=id)
update.Section = s
update.save()
sweetify.success(request, 'You did it', text='Your Form has been Updated',persistent='Hell yeah')
return render(request, 'Homepage/selectrecord.html')
这是我的html
{% load sweetify %}
{% sweetify %}
<form method="post" action="/studentrecords/" enctype="multipart/form-data">{% csrf_token %}
<table>
{% for student in myrecord %}
<tr>
<td>Control #</td>
<td><input type="text" name="id" value="{{student.id}}"></td>
<td><input type="submit"></td>
</tr>
<tr>
<td>Name: </td>
<td><input type="text" value="{{student.Student_Users.Firstname}} {{student.Student_Users.Lastname}} {{student.Student_Users.Middle_Initial}}"></td>
<td>Course/Track</td>
<td><input type="text" value="{{student.Courses}}"></td>
</tr>
<tr>
<td>Education Level: </td>
<td><input type="text" value="{{student.Education_Levels}}"></td>
<td>Strand: </td>
<td><input type="text" value="{{student.strands}}"></td>
</tr>
<tr>
<td>Section: </td>
<td>
<select name="section">
<option value="{{student.Section.id}}">{{student.Section}}</option>
{% for sections in section %}
<option value="{{sections.id}}">{{sections.Description}}</option>
{% endfor %}
</select>
</td>
<td>Payment Type: </td>
<td><input type="text" value="{{student.Payment_Type}}" class="myform"></td>
</tr>
{% endfor %}
</table>
</form>
我的settings.py
INSTALLED_APPS = [
#my apps
….
'sweetify'
]
SWEETIFY_SWEETALERT_LIBRARY = 'sweetalert2'
我没有收到任何错误,但没有弹出消息出现[[(sweetify)
models.py
:@receiver(models.signals.post_save, sender=StudentsEnrollmentRecord)
def update_enrollment_record_handler(sender, updated_instance, **kwargs):
"""This method is called after every call of StudentsEnrollmentRecord.save"""
sweetify.success(request, 'You did it', text='Your Form has been Updated',persistent='Hell yeah')
[第二个-POST旨在通过RestAPI创建对象,您应该切换到UPDATE(包括所有对象字段)或PUT(更新某些对象字段)。[第三-当在Sweetify行上方添加打印语句时会发生什么?该打印是否运行?如果不是,那么您的整个设置甚至都不会调用
studentrecords
方法,您将需要共享更多信息,以便我们复制情况和/或提供进一步建议。