我有一个评论部分html页面,每当我尝试填写字段并单击sumbit时,它会给出以下错误-Select a valid choice. That choice is not one of the available choices.
我已经从form.py中删除了widgets
,这给了我以下错误。后来我遇到了另一个错误-NOT NULL constraint failed: movie_comment.post_id
,在改变views.py
后,我能够成功发布
@login_required(login_url='/accounts/login/')
def comment_create(request, slug):
movie = Movie.objects.get(slug=slug)
if request.method == 'POST':
form = forms.CommentForm(request.POST, request.FILES)
if form.is_valid:
comment = form.save(commit=False)
comment.post = movie
comment.author = request.user
form.save()
return redirect('movies:movie_detail', slug=slug)
else:
form = forms.CommentForm()
return render(request, 'add_comment.html', {'form': form})
现在可以运行了