What is a good format of getting the parse from HTML using Django

34 Views Asked by At

I needed help for this small project that I am doing. I tried getting the output from a form in base.html through a function in Views.py. The value I am getting has an extra blank element in the QueryDict I have put the code below:

views.py


        def addToDo(request):
        contents = request.POST['content']
        print(contents)
        added_Time = timezone.now()
        print(added_Time)
        print(contents)
        return render(request,'index.html')

models.py


    class ToDoList(models.Model):
    ToDoText = models.TextField()
    ToDoDate = models.DateField()

base.html


<body>
<nav>
  <div class="container">
    <div class="nav-wrapper">
      <a href="#" class="brand-logo">To Do App</a>
    </div>
  </div>
</nav>

<div class="container">
  <div class="row">
    <div class="col">
        <h1>Good Day!</h1>
        <form class="form-inline" action="addToDo/" method="POST">
          <input type="text" name="content" placeholder='What are you planning today?'>
          <button class='btn waves-effect waves-light btn-small' type="submit" name="content">Submit</button>
        </form>
      {% block body_block %}
      {% endblock %}
    </div>
  </div>
</div>

The error is <QueryDict: {'content': ['Hello', '']}> instead of <QueryDict: {'content': ['Hello']}>

when print(contents) is given, the value is a blank instead of 'Hello

1

There are 1 best solutions below

0
On

Found the answer, the name in the tag in html to be removed to avoid extra "" in the output. Thanks!