Html 无法对审查表django实施星级评定
我目前正在Django上的一个餐馆评论网站上工作,但我在对我的评论进行星级评定时遇到了困难 这是我的Django代码: detail.htmlHtml 无法对审查表django实施星级评定,html,css,django,Html,Css,Django,我目前正在Django上的一个餐馆评论网站上工作,但我在对我的评论进行星级评定时遇到了困难 这是我的Django代码: detail.html <form method="POST" class="post-form"> <fieldset class="rating"> <input type="radio" id="star5" name="rating" value="5" /> <label class="
<form method="POST" class="post-form">
<fieldset class="rating">
<input type="radio" id="star5" name="rating" value="5" />
<label class="full" for="star5" title="Awesome - 5 stars"></label>
<input type="radio" id="star4half" name="rating" value="4half" />
<label class="half" for="star4half" title="Pretty good - 4.5 stars"></label>
<input type="radio" id="star4" name="rating" value="4" />
<label class="full" for="star4" title="Pretty good - 4 stars"></label>
<input type="radio" id="star3half" name="rating" value="3half" />
<label class="half" for="star3half" title="Meh - 3.5 stars"></label>
<input type="radio" id="star3" name="rating" value="3" />
<label class="full" for="star3" title="Meh - 3 stars"></label>
<input type="radio" id="star2half" name="rating" value="2half" />
<label class="half" for="star2half" title="Kinda bad - 2.5 stars"></label>
<input type="radio" id="star2" name="rating" value="2" />
<label class="full" for="star2" title="Kinda bad - 2 stars"></label>
<input type="radio" id="star1half" name="rating" value="1half" />
<label class="half" for="star1half" title="Meh - 1.5 stars"></label>
<input type="radio" id="star1" name="rating" value="1" />
<label class="full" for="star1" title="Sucks big time - 1 star"></label>
<input type="radio" id="starhalf" name="rating" value="half" />
<label class="half" for="starhalf" title="Sucks big time - 0.5 stars"></label>
</fieldset>
{% csrf_token %} {{ form.as_p }}
<button type="submit" class="save btn btn-default" style="width: 100px!important; margin-left: 40%!important; border: none!important; background-color:#ffbf24!important; outline: 0!important; color: white!important;">Send</button>
</form>
{% else %}
<center>
<h6 style="margin-left: 20px; text-align: center;">You must login to add a comment</h6></center>
</center><a href="{% url 'main_app:login' %}" class="btn btn-primary" style=" margin-left:45%!important; border: none!important; background-color:#ffbf24!important; outline: 0!important; color: white!important;">Login</a></center>
{% endif %}
</div>
</div>
</section>
基本上,我的目标是创建一个Django表单,用户可以在其中填写他们对餐厅的期望评级。但当我尝试这样做时,我失败了,因为星级评分要么不保存,要么无法在我的views.py
Django文件中有效地获取它们的值
我尝试过使用,但似乎无法获得我想要的结果,因为我只能在以前创建的数据库对象上使用库,而不能在新创建的数据库对象上使用库。我真的很感激能得到的任何反馈,并为我有一段时间没有发布的任何不清楚的事情道歉,如果需要,我将很高兴澄清具体发生了什么?“你期望/想发生什么事?”谢你的回答。我已经更新了我的答案你的打印声明中打印了什么?什么是
request.POST['rating']
设置为?@schillingt request.POST['rating']没有向控制台打印任何内容。具体发生了什么?“你期望/想发生什么事?”谢你的回答。我已经更新了我的答案你的打印声明中打印了什么?什么是request.POST['rating']
设置为?@schillingt request.POST['rating']未向控制台打印任何内容。
@login_required
def add_review_to_restraunt(request, pk):
restraunt = get_object_or_404(Restraunt, pk=pk)
if request.method == "POST":
form = ReviewForm(request.POST)
if form.is_valid():
print(form.cleaned_data['rating'])
review = form.save(commit=False)
review.restraunt = restraunt
review.user = request.user
review.save()
return redirect('detail', pk=restraunt.pk)
else:
form = ReviewForm()
return render(request, 'main_app/add_review_to_restraunt.html', {'form': form})