我从用户那里获取了一些输入,并将其存储在Django SQLite文件中,相同的数据正在获取它并显示在下拉列表中,但当用户选择一个值时,views.py中的所选值将为null
我也尝试过使用POST.get,但仍然从表单中得到NULL。你们谁能帮我找出我的错误吗
HTML文件:
<form method="post" action="/NewHandBook/ReadCobrand">{% csrf_token %}
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1" style="margin-top: 5px">
<ul class="nav navbar-nav">
<li class="dropdown" style="padding-right: 10px">
<select class="form-control" id="sel1" style="font-family: Courier">
<option name="NewEnvName"
value="xyz">xyz</option>
</select>
</li>
</ul>
<ul class="nav navbar-nav">
<li class="dropdown" style="font-family: Courier;font-size: 20px;color: ivory">
<input type='radio' name='CobranSelection' value="CobrandName" checked/>
<label for="edit-radios-lorem-tortor-erat" class="option"
>Cobrand
Name | </label>
<input type='radio' name='CobranSelection' value="CobrandId"/>
<label for="edit-radios-lorem-tortor-erat" class="option"
>Cobrand
Id </label>
</li>
</ul>
<div class="form-group">
<input type="text"
style="margin-top: -1px;font-family: Courier;width: 210px;margin-right: -10px"
class="form-control"
name="cobrand" placeholder="Eneter Cobrand detail here">
<button type="submit" class="btn btn-default"
style="margin-top: -31px;font-family: Courier;margin-left: 230px">
Submit
</button>
</div>
</div><!-- /.navbar-collapse -->
</form>
url.py
from django.conf.urls import url
from . import views
urlpatterns = [
url('login', views.login),
url('Home', views.fetch_all_env),
url('AddEnvironment', views.add_environment),
url('GetEnvironment', views.GetEnvironment),
url('ReadDb', views.readdb),
url('LearnCobrand', views.learncobrand),
url('ReadCobrand',views.knowcobrand)
]
views.py
def knowcobrand(request):
value_type = request.POST.get('CobranSelection')
cobrand_value = request.POST.get('cobrand')
env = request.POST.get('NewEnvName')
print(value_type)
print(cobrand_value)
print(env)
return render(request, 'CobrandView/CobrandInDepth.html')
You're looking for a ChoiceField which renders as a select html element by default.
Also make sure to check this, it's a more comprehensive guide of what you want
相关问题 更多 >
编程相关推荐