所以我创建了一个django网站,我有一个编辑按钮。 编辑显示一个弹出窗口,其中包含一些要编辑的表单。问题是要编辑的表单是空白的!而不是以前的数据。e、 g- ServerName=“Yossi”当我单击“编辑”而不是表单中的“Yossi”时,我什么都没有。在
我需要添加什么到索引.html或者PostEdit的类,这样我就可以在表单中保留以前的数据,而不是空白表单?在
在模型.py-在
from django.db import models
# Create your models here.
class serverlist(models.Model):
ServerName = models.CharField(max_length = 30)
Owner = models.CharField(max_length = 50)
Project = models.CharField(max_length = 30)
Description = models.CharField(max_length = 255)
IP = models.CharField(max_length = 30)
ILO = models.CharField(max_length = 30)
Rack = models.CharField(max_length = 30)
Status = models.CharField(max_length = 30)
#date = models.DateTimeField(auto_now=True)
在视图.py-在
^{pr2}$在服务器列表.html-在
<button type="button" class="btn btn-outline-primary" data-toggle="modal" href="#edit-server-{{server.id}}"
data-target="#Edit{{server.id}}">   Edit  <i class="fa fa-pencil"></i></button>
 
<div id ="Del{{server.id}}" class="modal fade" role="document">
<div class="modal-dialog" id="delete-server-{{server.id}}">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Delete Confirmation</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form action="{% url 'delete_post' server.id %}" method="post">{% csrf_token %}
<h6>Are you sure you want to delete {{ server.ServerName }}?</h6>
<br>
<center><input type="submit" class="btn btn-danger btn-md" value="Confirm"/>
<button type="submit" class="btn btn-secondary" data-dismiss="modal">Cancel</button></center>
</form>
</div>
</div>
</div>
</div>
<div class="modal fade bd-example-modal-sm" id="Edit{{server.id}}" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Edit Server</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form action="{% url 'edit_post' server.id %}" method="post"> {% csrf_token %}
<!--<center> {{ form.as_p }} </center> -->
{% for field in form %}
<div class="fieldWrapper">
{{ field.errors }}
<!-- {{ field.label_tag }} -->
<small><b>{{ field.html_name }}<p align="left"></b> {{ field }}</small> </p>
{% if field.help_text %}
<p class="help">{{ field.help_text|safe }}</p>
{% endif %}
</div>
{% endfor %}
<center><h2> <button type="submit" class="save btn btn-success btn-lg">Confirm</button></h2>
<h2><button type="submit" class="btn btn-secondary" data-dismiss="modal">Cancel</button></h2></center>
</form>
</td>
</div>
</tr>
{% endfor %}
目前没有回答
相关问题 更多 >
编程相关推荐