所以我想将我的表单发布到Django Admin面板(到小部件中)。 我已经用HTML和CSS制作了表单并设置了样式,我只想将该信息发布到我的数据库中,并能够在管理面板的小部件中自己查看它,所以,我只想发布表单数据
所以我想知道这样做的最佳方法-有任何建议吗?
我要:将用户输入内容发布到Django管理面板小部件
我当前的表单是这样的-(我正在使用Bootstrap 4,Django VERSION 2,1,1)
数据库:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
HTML:
<div class="row">
<div class="col-sm-4"></div>
<div class="col-sm-4">
<form method="post">
{% csrf_token %}
<select class="custom-select custom-select-lg mb-3" name="typeoflocation" type="text" id="DropdownMenu">
<option selected>What type of a location is it?</option>
<option value="1">Restaurant</option>
<option value="2">Bar</option>
<option value="3">Office</option>
<option value="4">Hotel</option>
<option value="5">Other</option>
</select>
<select class="custom-select custom-select-lg mb-3" name="location" type="text" id="DropdownMenu">
<option selected>In which city is your location?</option>
<option value="1">Melbourne</option>
<option value="2">Sydney</option>
<option value="3">Canberra</option>
</select>
<div class="form-group">
<input type="text" class="form-control" id="formGroupExampleInput" name="nameoftheplace" placeholder="WHAT IS THE NAME OF THE LOCATION?">
</div>
<div class="form-group">
<input type="text" class="form-control" id="formGroupExampleInput" name="url" placeholder="WHAT IS THE WEBSITE URL?">
</div>
<div class="form-group">
<input type="text" class="form-control" id="formGroupExampleInput" name="address" placeholder="WHAT IS THE STREET ADDRESS?">
</div>
<div class="form-group">
<input type="text" class="form-control" id="formGroupExampleInput" name="capacity" placeholder="WHAT IS THE SEATING CAPACITY">
</div>
<select class="custom-select custom-select-lg mb-3" name="time" type="text" id="DropdownMenu">
<option selected>At what time does dinner service typically start?</option>
<option value="1">4:00pm</option>
<option value="2">4:30pm</option>
<option value="3">5:00pm</option>
<option value="4">5:30pm</option>
<option value="5">6:00pm</option>
<option value="6">6:30pm</option>
</select>
<select class="custom-select custom-select-lg mb-3" name="numberofdays" type="text" id="DropdownMenu">
<option selected>Which days would you like SideSpacer to operate in your space?</option>
<option value="1">7 Days a week</option>
<option value="2">Weekdays only</option>
<option value="3">Weekends only</option>
<option value="4">Monday</option>
<option value="5">Tuesday</option>
<option value="6">Wednesday</option>
<option value="7">Thursday</option>
<option value="8">Friday</option>
<option value="9">Saturday</option>
<option value="10">Sunday</option>
</select>
<div class="form-group">
<input type="text" class="form-control" id="formGroupExampleInput" name="name" placeholder="YOUR FIRST NAME">
</div>
<div class="form-group">
<input type="text" class="form-control" id="formGroupExampleInput" name="lastname" placeholder="YOUR LAST NAME">
</div>
<div class="form-group">
<input type="text" class="form-control" id="formGroupExampleInput" name="phone" placeholder="YOUR PHONE NUMBER">
</div>
<div class="form-group">
<input type="text" class="form-control" id="formGroupExampleInput" name="email" placeholder="YOUR EMAIL ADDRESS">
</div>
<select class="custom-select" name="reach" multiple>
<option selected>What's the best way to reach you?</option>
<option value="1">Phone</option>
<option value="2">Text</option>
<option value="3">E-mail</option>
</select>
<button name="submit" method="POST" class="btn btn-outline-secondary" type="submit" style="margin-top:25px; padding-left:20px; padding-right: 20px;
padding-top: 12px; padding-bottom:12px; margin-bottom: 20px;" value="OK">Submit a Space</button>
<p class="text-muted">(Our Hospitality Team will follow up with you directly if they feel<br> your location is a good fit for SideSpacer.)</p>
</form>
</div>
<div class="col-sm-4"></div>
</div>
</div>
答案 0 :(得分:0)
您将要为自己的问题和答案创建models,以便您可以存储答复并创建Django form以处理用户输入。
Django网站上有一些非常扎实的入门文档。 This particular page概述了如何使用模型创建数据库条目/结构以及如何从管理控制台访问它们。如果您需要了解如何显示表单本身,建议您使用Django研究表单。
如果您更喜欢视频并希望将所有信息集中在一个地方,那么this tutorial涵盖了我在这里提到的大部分内容,即使不是全部。
资源: