【发布时间】:2020-05-22 01:12:43
【问题描述】:
我已经阅读了有关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>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@9"></script>
<script>
Swal.fire(
'Good job!',
'Data Updated!',
'success'
)
</script>
我的设置.py
INSTALLED_APPS = [
#my apps
….
'sweetify'
]
SWEETIFY_SWEETALERT_LIBRARY = 'sweetalert2'
我没有收到任何错误,但没有弹出消息(sweetify)
【问题讨论】:
-
缺少文档且应用不包含所需的 javascript 文件,因此假设您在模板中包含 SweetAlert javascript 库。你的例子中没有它。您是否在基本模板中包含了必要的代码?
-
我更新了问题。我在我的html中发布脚本
标签: django sweetalert sweetalert2