OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Passing date value to HTML form in django framework

  • Thread starter Thread starter Douglas Baldwin
  • Start date Start date
D

Douglas Baldwin

Guest
I am building my first application with Django. I am trying to make a template form to update values in a row in a table in a database. I want to populate all the forms fields with the existing values from the database. I can pass dates in as text just fine:

This displays my date:

Code:
<input type="text" class="form-control" value="{{ table.date }}">

but when I try the same value into a date field, it remains blank with I render

This displays a blank date field:

Code:
<input type="date" class="form-control" value="{{ table.date }}">

I assume this has to do with handling date formatting. Is there an easy way to handle this in the html? or does it require backend work?

Any python code I tried to write into the template resulted in a 404. Still learning what the capabilities are. From what I have read I am guessing correct way to do this is with a function in my model, but I was hoping I could write something to convert the date in my template.

My view is basic:

Code:
def update(request, id):
    table = table.objects.get(pk=id)
    return render(request, 'app/tempate.html', {'table' : table})
<p>I am building my first application with Django. I am trying to make a template form to update values in a row in a table in a database. I want to populate all the forms fields with the existing values from the database. I can pass dates in as text just fine:</p>
<p>This displays my date:</p>
<pre><code><input type="text" class="form-control" value="{{ table.date }}">
</code></pre>
<p>but when I try the same value into a date field, it remains blank with I render</p>
<p>This displays a blank date field:</p>
<pre><code><input type="date" class="form-control" value="{{ table.date }}">
</code></pre>
<p>I assume this has to do with handling date formatting. Is there an easy way to handle this in the html? or does it require backend work?</p>
<p>Any python code I tried to write into the template resulted in a 404. Still learning what the capabilities are. From what I have read I am guessing correct way to do this is with a function in my model, but I was hoping I could write something to convert the date in my template.</p>
<p>My view is basic:</p>
<pre><code>def update(request, id):
table = table.objects.get(pk=id)
return render(request, 'app/tempate.html', {'table' : table})
</code></pre>
 
Top