django - CRUD 在同一页 DJANGO
问题描述
我正在尝试使用 django 仅使用一个 html 页面进行 CRUD,但我已经遇到了第一个问题,当使用导航选项卡时,当我单击“创建/编辑”选项卡时,我无法加载表单,也许它有与网址有关,但我不知道。
索引.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>Ordens de Serviço</h2>
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#list">Ordens de Serviço</a></li>
<li><a data-toggle="tab" href="#create-update">Criar/Editar</a></li>
<li><a data-toggle="tab" href="#detail">Ver</a></li>
</ul>
<div class="tab-content">
<div id="list" class="tab-pane fade in active">
<h3>Ordens de Serviço</h3>
<table class="table">
<thead>
<tr>
<th>Nome</th>
<th>TAG</th>
<th>nivel</th>
</tr>
</thead>
<tbody>
{%for equipamento in equipamentos %}
<tr>
<td>{{equipamento.nome}}</td>
<td>{{equipamento.tag}}</td>
<td>{{equipamento.nivel}}</td>
<td><a><button class="btn btn-primary">Editar</button></a></td>
</tr>
{%endfor%}
</tbody>
</table>
</div>
<div id="create-update" class="tab-pane fade">
<h3>Criar/Editar</h3>
<form method="post">
{% csrf_token %}
{{form}}
</form>
</div>
<div id="detail" class="tab-pane fade">
<h3>Menu 2</h3>
<p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam.</p>
</div>
</div>
</div>
<script>
</script>
</body>
</html>
视图.py:
class ArvoreListView(ListView):
queryset = Arvore.objects.all()
template_name = 'example/index.html'
context_object_name = 'equipamentos'
class ArvoreCreateView(CreateView):
form_class = ArvoreModelForm
model = Arvore
template_name = 'example/create.html'
网址.py
urlpatterns = [
path('', ArvoreListView.as_view(), name='list'),
path('create/', ArvoreCreateView.as_view(), name='create'),
]
解决方案
推荐阅读
- python-3.x - PyG 对象。带有 GTK 的 Python。树视图问题
- c# - 绑定到任务
属性并将 IsAsync 设置为 true - python-3.x - 类型错误:+ 的不支持的操作数类型:'slice' 和 'int' 与 bt 回测
- php - 将毫秒添加到 datetime obj
- python - 从 lambda 表达式返回值
- android - 在固定数量的片段之间滑动
- jquery - 如何通过拖放将html内容添加到带有选定图像图标的可排序区域?
- html - 在手机上查看时右侧出现怪线
- ios - 在 Swift 中从字符串中解析多个双精度数
- php - Foreach 总是删除最后一个文件 PHP