【发布时间】:2020-10-01 01:24:29
【问题描述】:
所以我编写了一个 HTML 页面,所有输入都准备就绪。我打算在我的 python HTTP 服务器上使用它,但我将使用 Django,因为人们一直告诉我它更适合服务器处理。我在 django 上玩过 forms.py,但问题是你必须在 forms.py 中创建表单,然后它为你构造 HTML。我已经准备好 HTML,所以有没有办法让我只处理表单数据,而不必在 forms.py 中再次重写我的整个表单?
这是我希望 Django 处理和打印的 HTML 和表单:
{% load static %}<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="{% static 'polls/style.css' %}">
</head>
<body>
<h1 class="mx-auto text-center mt-8 px-0 py-8 border border-4 border-solid border-gray-600"
style="width: 700!important;">CHECKBOX INPUT</h1>
<div class="flex h-full mx-auto">
<form action="/polls/thanks/" method="post">
{% csrf_token %}
<div class="w-3/4 py-10 px-8">
<table class="table-auto">
<thead>
<tr>
<th class="py-10 h-4">
<div class="mr-64">
<input type="checkbox" class="form-checkbox h-8 w-8">
<label class="ml-4">test</label>
</div>
</th>
</tr>
<tr>
<th class="py-10 h-4">
<div class="mr-64">
<input type="checkbox" class="form-checkbox h-8 w-8">
<label class="ml-4">test</label>
</div>
</th>
</tr>
<tr>
<th class="py-10 h-4">
<div class="mr-64">
<input type="checkbox" class="form-checkbox h-8 w-8">
<label class="ml-4">test</label>
</div>
</th>
</tr>
<tr>
<th class="py-10 h-4">
<div class="mr-64">
<input type="checkbox" class="form-checkbox h-8 w-8">
<label class="ml-4">test</label>
</div>
</th>
</tr>
<tr>
<th class="px-4 py-10 h-4">
<div class="mx-auto">
<span>TEXT INPUT:</span>
<input type="text" class="form-input mt-4">
<select>
<option value="value1" selected>DROPDOWN</option>
<option value="valeu2">Value 2</option>
<option value="valeu3">Value 3</option>
</select>
</div>
</th>
</tr>
<tr>
<th class="px-4 py-10 h-4">
<div class="mx-auto">
</div>
</th>
</tr>
<tr>
<th class="px-4 py-10 h-4">
<div class="mx-auto">
<input type="submit" value="Submit" class="bg-gray-600 p-4 border-0 border-solid rounded-lg">
</div>
</th>
</tr>
</thead>
</table>
</div>
</form>
</div>
</body>
</html>
谢谢
【问题讨论】:
-
这取决于你的html。
-
如果有帮助,我会把它添加到帖子中