Reputation: 165
So I've coded an HTML page with all the inputs ready to go. I was going to use this on my python HTTP server but instead I am going to use Django because people have been telling me its much better for server handling. I played around with the forms.py on django but the problem is there you have to create the forms in forms.py and then it constructs the HTML for you. I already have the HTML ready so is there a way for me to just process the form data without having to rewrite my whole form again in forms.py?
Here is the HTML and the form I want Django to process and print:
{% 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>
Thanks
Upvotes: 2
Views: 1203
Reputation: 738
Sure, you don't have to create model forms, they are just made for convenience. Just submit the form you made, then, in the corresponding view you can get your data from the request using the names of your tags. Of course, you should add names to your tags if hey don't have ones. For example: <select name='tag_name'>
Get your data this way:
data = request.POST.get('tag_name')
Upvotes: 3