# update a html form in django

**URL:** <https://forum.djangoproject.com/t/update-a-html-form-in-django/15547>\
**Category:** Forms & APIs\
**Created:** [August 22, 2022, 4:48pm UTC](https://forum.djangoproject.com/t/update-a-html-form-in-django/15547 "2022-08-22T16:48:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gentility01](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/gentility01/32/7790_2.png) [@Gentility01](https://forum.djangoproject.com/u/Gentility01)\
**Post date:** [August 22, 2022, 4:48pm UTC](https://forum.djangoproject.com/t/update-a-html-form-in-django/15547/1 "2022-08-22T16:48:32Z")

</div>

i want to update a form using only html form i need help please

```auto
from django.shortcuts import render, redirect
from .models import Todo
from django.shortcuts import render, get_object_or_404
from django.contrib import messages
# Create your views here.

def create(request):
    if request.method == 'POST':
        title = request.POST.get('title')
        description = request.POST.get('description')
        priority = request.POST.get('priority')
        completed = request.POST.get('completed') 
        if completed =='on':
            completed=True
        else:
            completed=False
        print('ssssssssssssssssss',completed)
        create_todo = Todo.objects.create(title=title, description=description, priority=priority, completed=completed)
        # if create_todo.is_valid():
        create_todo.save()
        return redirect('view_doto')
    return render(request, 'home/create.html')

def update(request, id):
    postobj= get_object_or_404(Todo, id=id)
    if request.method == 'POST':
        if request.POST.get('title') and request.POST.get('description') and request.POST.get('priority') and request.POST.get('completed') :
            Todo.objects.filter(id = id).update(title= request.POST.get('title'), description= request.POST.get('description'), priority= request.POST.get('priority'), completed= request.POST.get('completed'))
            messages.success(request, "The post was successfully updated")

            context={'postobj': postobj}
    else:
        context={'postobj': postobj,'error': 'The post was not successfully updated. The title and content must be filled out.'}
    # context={'postobj': postobj}
        return render(request, 'home/update.html',context)

def view_doto(request):
    posts = Todo.objects.all().order_by('-id')
    return render(request, 'home/index.html', {'posts':posts})

```

this is my views.py

```auto
{% extends "base.html" %}

{% block content %}

<div class="header-bar">
    <a href="{% url 'view_doto' %}">&#8592; Back</a>
</div>

<div class="card-body">
    <form method="POST" action="{% url 'create' %}">{% csrf_token %}
       
        <div class="form-outline">
            <label class="form-label" for="formControlLg">Title</label>
            <input type="text" name="title" value="{{ postobj.title }}" class="form-control form-control-lg" />
          </div>
          
          <div class="form-outline">
            <label class="form-label" for="formControlDefault">Description</label>
            <input type="text" name="description" value="{{ postobj.description}}" class="form-control" />
            
          </div>
          
          <div class="form-outline">
            <label class="form-label" for="typeNumber">Priority</label>
            <input type="number" name="priority" value="{{postobj.priority}}" class="form-control" />
          </div><br>

          <div class="form-check">
            <input class="form-check-input" type="checkbox" value="{{ postobj.completed}}" name="completed"> Completed
            <!-- <label class="form-check-label" for="flexCheckDefault"> -->
             
            </label>
          </div>
          
          <br>

          <input class="button" type="submit" value="search">
      </form>

</div>

{% endblock content%}

```

this is the template for the update…please how can i fix this i eed help

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [August 22, 2022, 5:06pm UTC](https://forum.djangoproject.com/t/update-a-html-form-in-django/15547/2 "2022-08-22T17:06:50Z")

</div>

The easiest way to get it all working correctly would be to fix your template and view to use a Django form. It’s going to prevent a lot of problems going forward if you take the time now to do this the way that Django intends for it to be done.

---

<div class="post-metadata">

**Author:** ![Gentility01](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/gentility01/32/7790_2.png) [@Gentility01](https://forum.djangoproject.com/u/Gentility01)\
**Post date:** [August 22, 2022, 6:18pm UTC](https://forum.djangoproject.com/t/update-a-html-form-in-django/15547/3 "2022-08-22T18:18:10Z")

</div>

thanks alot sir but can i use it in APIs too

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [August 22, 2022, 6:57pm UTC](https://forum.djangoproject.com/t/update-a-html-form-in-django/15547/4 "2022-08-22T18:57:00Z")

</div>

What specifically do you mean? The example and question you posed is a standard POST form submission. How do APIs fit into this?

---

<div class="post-metadata">

**Author:** ![Gentility01](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/gentility01/32/7790_2.png) [@Gentility01](https://forum.djangoproject.com/u/Gentility01)\
**Post date:** [August 22, 2022, 6:58pm UTC](https://forum.djangoproject.com/t/update-a-html-form-in-django/15547/5 "2022-08-22T18:58:42Z")

</div>

just asking if i can still use django forms during APIs

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [August 22, 2022, 7:50pm UTC](https://forum.djangoproject.com/t/update-a-html-form-in-django/15547/6 "2022-08-22T19:50:27Z")

</div>

A Django form is a Python object representing an HTML form, along with a lot of functionality baked in.

That functionality “activated” when you either initially render the form to HTML as an unbound form, or when data is submitted via POST to a view which then binds the submitted data to that form.

It actually doesn’t matter what is sending or receiving that data as long as the view knows what to do with what is being sent to it.

---

<div class="post-metadata">

**Author:** ![Gentility01](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/gentility01/32/7790_2.png) [@Gentility01](https://forum.djangoproject.com/u/Gentility01)\
**Post date:** [August 22, 2022, 8:40pm UTC](https://forum.djangoproject.com/t/update-a-html-form-in-django/15547/7 "2022-08-22T20:40:51Z")

</div>

thanks sir i appreciate
