我正在尝试从一个Post Request到我的Django后端以Modal显示数据。
$(function (e) {
$(".form-select").change(function (event) {
let $vid = this.value;
let $hostname =$(this).closest('tr').find('td.hostname').text();
for(var i = 0; i < this.options.length; i++){ //deselect the option
this.options[i].selected = false;
}
$.ajax({
type: "POST",
url: '/api/vulinfo',
data: {
'client': $hostname,
'vid' : $vid,
'csrfmiddlewaretoken': '{{ csrf_token }}'
},
success: function(response) {
$('#vulmodal').modal("show");
}
});
});
正确的hostname
和vid
被发送到我的Django视图。
def vulInfo(request):
qs = clientvul.objects.all().filter(client=request.POST['client']).filter(VID=request.POST['vid'])
return render(request,'browseDB.html', {'vuldata':qs}, status=200)
我尝试访问数据在模态,但它总是空的
<div class="modal fade bd-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true" id="vulmodal">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<h1>Path:{{vuldata.path}} </h1>
text text text
</div>
</div>
</div>
Models.py
from django.db import models
from django.contrib import admin
class client(models.Model):
client= models.CharField(max_length=50,primary_key=True)
user= models.CharField(max_length=100)
vuls = models.ManyToManyField(
'vul',
through='clientvul',
related_name='client'
)
class vul(models.Model):
vid=models.IntegerField(primary_key=True)
cvelist=models.CharField(max_length=50)
cvsscore=models.FloatField(max_length=5)
serverity=models.CharField(max_length=25)
title=models.CharField(max_length=1000)
summary=models.CharField(max_length=1000)
class clientvul(models.Model):
client= models.ForeignKey(client, on_delete=models.CASCADE)
vid=models.ForeignKey(vul, on_delete=models.CASCADE)
path=models.CharField(max_length=1000)
isActive=models.BooleanField(default=True)
class Meta:
constraints = [
models.UniqueConstraint(
fields=['client', 'VID'], name='unique_migration_host_combination' # legt client und VID als Primarykey fest
)
]
admin.site.register(client)
admin.site.register(vul)
admin.site.register(clientvul)
1条答案
按热度按时间vd8tlhqk1#
你在h1中有一个值“path”:
联系我们
但是在你的clientvul模型中,它是用小写的p写的,所以你可以做这样的修改:联系我们