|
楼主 |
发表于 2024-1-17 18:12:26
|
显示全部楼层
{% load static %}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>eCommerce template By Adobe Dreamweaver</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
{# <link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}">#}
<link rel="stylesheet" href="{% static 'css/eCommerceStyle.css' %}">
{# <script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js"></script>#}
<script src="{% static 'js/jquery.min.js' %}"></script>
<script src="{% static 'js/bootstrap.js' %}"></script>
<script src="{% static 'js/jquery-3.6.0.min.js' %}"></script>
{# <script src="{% static 'js/bootstrap.bundle.min.js' %}"></script>#}
<script src="{% static 'js/bootstrap.min.js' %}"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div id="mainWrapper">
<header>
<!-- This is the header content. It contains Logo and links -->
<!-- <img src="logoImage.png" alt="sample logo"> -->
<!-- Company Logo text -->
{# <div id="headerLinks"><a href="#" title="Login/Register">登陆/退出</a></div>#}
<div class="dropdown" style="position: absolute; top: 10px; right: 10px;">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
{{ request.session.info.name }}
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
<li><a href="#">设置</a></li>
<li><a href="http://127.0.0.1:8000/zx/" title="Link">退出</a></li>
</ul>
</div>
</header>
<div id="content">
<section class="sidebar">
<!-- This adds a sidebar with 1 searchbox,2 menusets, each with 4 links -->
<div id="menubar">
<nav class="menu">
<ul>
<!-- List of links under menuset 1 -->
<li>
<a href="#" title="Link">首页</a></li>
<li><a href="#" title="Link">监控网站</a></li>
<li><a href="#" title="Link">博客网站</a></li>
<li><a href="#" title="Link">容器网站</a></li>
<li><a href="http://127.0.0.1:8000/rootuseradd/" title="Link">测试python界面</a></li>
<li class="notimp"><!-- notimp class is applied to remove this link from the tablet and phone views --><a href="#" title="Link"> </a></li>
</ul>
</nav>
<nav class="menu">
<h2>设置 </h2>
<!-- Title for menuset 2 -->
<hr>
<ul>
<!--List of links under menuset 2 -->
<li><a href="#" title="Link">设置 </a></li>
<li class="notimp"><!-- notimp class is applied to remove this link from the tablet and phone views --><a href="#" title="Link">退出</a></li>
</ul>
</nav>
</div>
</section>
<section class="mainContent">
<div class="productRow"><!-- Each product row contains info of 3 elements -->
<style>
.panel {
border: none;
}
.table {
text-align: center;
margin-left: auto;
margin-right: auto;
}
</style>
<body>
<div class="bs-example" data-example-id="panel-without-body-with-table">
<div class="panel panel-default">
<table class="table">
<tr>
<th scope="row"></th>
<td><a href="http://127.0.0.1:8000/useradd/" title="Link">用户添加</a></td>
<td><a href="http://127.0.0.1:8000/view/" title="Link">用户查看</a></td>
<td><a href="http://127.0.0.1:8000/user_add/" title="Link">部门添加</a></td>
<td><a href="http://127.0.0.1:8000/user_add/" title="Link">部门查看</a></td>
</tr>
</table>
</div>
</div>
</body>
<div class="bs-example" data-example-id="panel-without-body-with-table">
<div class="panel panel-default">
<!-- Default panel contents -->
<div class="panel-heading">用户信息
<form method="get">
</form>
<div class="input-group">
<input type="text" name="q" class="form-control" placeholder="Search for...">
</form>
<span class="input-group-btn">
<button class="btn btn-default" type="submit"><span class="glyphicon glyphicon-search" aria-hidden="true"></span></button>
</span>
</div><!-- /input-group -->
</div><!-- /.col-lg-6 -->
</div><!-- /.row -->
<!-- Table -->
<table class="table">
<tr>
{% for s in deat %}
<td align="left">{{ s.id }}</td>
<td align="left">{{ s.get_j_display }}</td>
<td align="left">{{ s.bt }}</td>
<td align="left">{{ s.detail }}</td>
<td align="left">{{ s.user }}</td>
<td>
<input uid="{{ s.id }}" type="button" class="btn btn-primary btn-xs btn-edit1" value="编辑" >
<input uid="{{ s.id }}" class="btn btn-danger btn-xs btn-delete" type="button" value="删除">
</td>
<!-- 删除数据模态框 -->
<div class="modal fade" id="deleteuid" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span></button>
{# <h4 class="modal-title" id="myModalLabel">删除</h4>#}
</div>
<div class="modal-body">
确认要删除吗?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
<button id="date2" type="submit" class="btn btn-primary">提交</button>
</div>
</div>
</div>
</div>
<!-- 编辑数据模态框 -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="viewTitle" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="viewTitle">编辑数据</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
{% for f in form %}
<div class="form-group">
{{ f.label }} : {{ f }}
<span class="error-msg" style="color:red; postition:absolute;"></span>
</div>
{% endfor %}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
<button id="eitd" type="button" class="btn btn-primary">保存</button>
</div>
</div>
</div>
</div>
</tr>
{% endfor %}
</table>
<script>
var DELETE_ID;
$(function () {
console.log("aja2 function called");
bb();
delete1();
})
function bb() {
$(".btn-edit1").click(function() {
var uid =$(this).attr("uid")
$.ajax({
url: "/ajaview",
type: "get",
data :{
uid: uid
},
dataType: "JSON",
success:function (res){
if(res.status){
$.each(res.data,function (name,value){
$("#id_" + name).val(value);
})
$('#myModal').modal('show');
console.log(res);
}else{
alert(res.error);
}
}
})
});
}
$(function et() {
$("#eitd").click(function() {
$.ajax({
url: "/ajeit",
type: "POST",
data: $("#btn-edit1").serialize() + "&uid=" + DELETE_ID,
dataType: "JSON",
success: function (res) {
if (res.status) {
console.log("保存成功");
// 关闭模态框
$('#myModal').modal('hide');
} else {
console.log("保存失败");
}
},
error: function (xhr, textStatus, errorThrown) {
console.log("请求错误:" + errorThrown);
}
});
});
});
function delete1() {
$(".btn-delete").click(function() {
$('#deleteuid').modal('show');
DELETE_ID=$(this).attr("uid");
var uid=$(this).attr("uid");
console.log(uid);
});
}
$(function () {
$("#date2").click(function() {
console.log("date2");
$.ajax({
url: "/ajdelete",
type: "GET",
data: {
uid: DELETE_ID
},
dataType: "JSON",
success: function (res) {
if (res.status) {
location.reload(); // 刷新界面的js代码
} else {
alert(res.error);
}
}
});
});
});
</script>
</body>
<ul class="pagination">
{{ ymm }}</ul>
</tr>
</tbody>
</table>
</div>
</div>
</article>
</div>
{% block b %}{% endblock %}
</section>
</div>
<footer>
<!-- This is the footer with default 3 divs -->
<div>
<p>没有数据</p>
</div>
<div>
<p>没有数据</p>
</div>
<div class="footerlinks">
<p><a href="#" title="Link">Link 1 </a></p>
<p><a href="#" title="Link">Link 2</a></p>
<p><a href="#" title="Link">Link 3</a></p>
</div>
</footer>
</div>
</body>
</html>
urls 文件路径
path('aj/', views.aj),
path('ajadd/', views.ajadd),
path('ajxs/', views.ajxs),
path('ajdelete', views.ajdelete),
path('ajaview', views.ajaview),
path('ajeit', views.ajeit),
view文件
def aj(request):
form = Aj()
return render(request, "aj.html",{"form":form})
import json
from django.http import HttpResponse
from django.forms.utils import ErrorDict
# @csrf_exempt
def ajadd(request):
form = Aj(data=request.POST)
if form.is_valid():
form.instance.user_id = request.session['info']['id']
form.save()
data = {"status": True}
return HttpResponse(json.dumps(data), content_type="application/json")
data = {"status": False,'error':form.errors}
return HttpResponse(json.dumps(data,ensure_ascii=False), content_type="application/json")
def ajxs(request):
from app.fenye import Cs
form = Aj()
n = request.GET.get('q', "")
ss = models.aj.objects.filter(
Q(id__icontains=n)
)
css = Cs(request, ss, n)
cz = {"deat": css.ssxs, "ymm": css.html,"form":form}
return render(request, "ajxs.html",cz)
def ajdelete(request):
uid=request.GET.get('uid')
exists=models.aj.objects.filter(id=uid).exists()
if not exists:
return JsonResponse({"status":False,"error":"not"})
models.aj.objects.filter(id=uid).delete()
return JsonResponse({"status":True})
def ajaview(request):
uid = request.GET.get("uid")
row = models.aj.objects.filter(id=uid).values("j","bt","detail").first()
result = {"status" :True,"data":row}
if not row:
return JsonResponse({"status": False, "error": "not11"})
return JsonResponse(result)
def root(request):
from app.fenye import Cs
form = Aj()
n = request.GET.get('q', "")
ss = models.aj.objects.filter(
Q(id__icontains=n)
)
css = Cs(request, ss, n)
cz = {"deat": css.ssxs, "ymm": css.html,"form":form}
return render(request, "cs.html",cz)
class ajajeit(forms.ModelForm):
# daa = forms.CharField(disabled=True,label="age")
# name = forms.CharField(min_length=3,label="用户名")
class Meta:
model = models.aj
fields = [ "j","bt","detail"]
def ajeit(request):
uid = request.GET.get("uid")
row= models.aj.objects.filter(id=uid).first()
if not row:
return JsonResponse({"status": False, "error": "not11"})
form = ajajeit(data=request.POST, instance=row)
if form.is_valid():
form.save()
return JsonResponse({"status":True})
return JsonResponse({"status": False, "error": form.error}) |
|