在基于类的视图中提交表单时遇到问题。我在详细信息视图中使用FormMixin,提交表单时出现405错误。我已经尝试过砍断和更改视图中的代码,但是似乎没有任何效果。
模型
class Bid(models.Model):
author = models.ForeignKey(User, on_delete=models.CASCADE)
tender = models.ForeignKey(Tender, on_delete=models.CASCADE, null=True)
title = models.CharField(max_length=100)
specification = models.TextField()
timeline = models.CharField(max_length=100)
date_posted = models.DateTimeField(default=timezone.now)
price = models.IntegerField()
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse('bid-detail', kwargs={'pk': self.pk})
观看次数
class TenderDetailView(FormMixin, LoginRequiredMixin, DetailView):
model = Tender
template_name = 'it_me/tender_detail.html'
form_class = BidForm
def get_success_url(self):
return reverse('tender-detail', kwargs={'pk': self.object.id})
def get_context_data(self, **kwargs):
context = super(TenderDetailView, self).get_context_data(**kwargs)
context['form'] = BidForm(initial={'post': self.object})
return context
def post(self, request, *args, **kwargs):
self.object = self.get_object()
form = self.get_form()
if form.is_valid():
return self.form_valid(form)
else:
return self.form_invalid(form)
def form_valid(self, form):
form.save()
return super(TenderDetailView, self).form_valid(form)
表格
class BidForm(forms.ModelForm):
class Meta:
model = Bid
fields = ('title', 'specification', 'timeline', 'price')
模板
<div class="content-section">
<form method="POST">
{% csrf_token %}
<fieldset class="form-group">
{{ form|crispy }}
</fieldset>
<div class="form-group">
<button class="btn btn-outline-info" type="submit"> Post Bid </button>
</div>
</form>
</div>
{% for bid in tender.bids.all %}
<div class=" col-md-12 comment">
<div class="date">{{ bid.date_posted|date:"F d, Y" }}</div>
<strong>{{ bid.author }}</strong>
</div>
{% empty %}
<p>No Bids Yet </p>
{% endfor %}
网址
path('tender/<int:pk>/', TenderDetailView.as_view(), name='tender-detail')
真的会很感激任何帮助,因为我很沮丧。
答案 0 :(得分:0)
hread::hread()
{
MutexSend.lock();
restart=false;
abort=false;
MutexSend.unlock();
}
hread::~hread()
{
}
void hread::run()
{
emit transfer(&pkg);
}
不支持发布请求。它旨在显示实例详细信息。如您在docs中所见,该视图仅支持get方法。要更新您的实例,可以使用DetailView
。 UpdateView是用于处理更新操作的通用视图。您还可以将这些文档页面用于基本做法,例如在UpdateView
中显示实例详细信息。