[Fixed]-Django ModelForm fields not rendering

1👍

Please add you feeds view to the question.

Something like this should work for add comment:

def add_comment(request, feed_id, ):
    try:
        feed_instance = Feed.objects.get(id=feed_id)
    except Feed.DoesNotExist:
        raise Http404

    form = CommentForm(request.POST or None)

    if form.is_valid():
        comment = form.save(commit=False)
        comment.username = request.user
        comment.pub_time = timezone.now()
        comment.feed = feed_instance
        comment.save()

    return HttpResponseRedirect('/feeds/')

and for your feeds view:

def feeds(request):
    context = {
        'form': CommentForm(),
        'feeds': Feed.objects.all(),
    }

    return render(request, 'feeds.html', context)

Leave a comment