Skip to content Skip to sidebar Skip to footer

Django: Proper Way To Handle Form With Post To The Same Page

I am new to Django and have completed the 7 part tutorial on their website. Part four of their tutorial introduces a form on the page details which posts to votes (a view that does

Solution 1:

You could do something like this,

def post_to_self_page(request, object_id):
    obj = get_object_or_404(Obj, pk=object_id)
    if request.method == 'POST':
        obj.attribute_of_obj = request.POST['attribute_of_obj'] 
        obj.save() 
    context = { 'obj': obj, }
    return render(request, 'my_app/post_to_self_page.html', context)

Post a Comment for "Django: Proper Way To Handle Form With Post To The Same Page"