7👍
✅
The problem is value="{{m.dob|date:'d/m/Y'}}"
which must be specified as value="{{m.dob|date:'Y-m-d'}}"
1👍
Dude, your question is not clear. But for now, I am assuming you are new to Django.
Your DB value is not populating in the template. In order to show the value, you must do two steps:
- First query the model object
- Pass it through additional context dictionary from the Django view.
from django.views.generic import View
from django.shortcuts import render
class Home(View):
template_name = "home.html"
def __init__(self, **kwargs):
pass
def get(self, request):
# Fetch your object here. ID or any other
myObj = MyModel.objects.get(id=1)
# Third argument is the conext dictionary
return render(request,self.template_name,{'myObj': myObj})
Now just use that myObj
in your template with the following syntax.
<tr><td>Date of Birth</td><td><input type="date" name="DOB" value="{{myObj.dob|date:"d/m/Y"}}" required=True></td></tr>
Here this code is in home.html.
1👍
If using ModelForm and passing that form object to template, then it should be
value="{{m.dob.value|date:'Y-m-d'}}"
- [Django]-Autocomplete with django-autocomplete-light’s
- [Django]-Django – Alternatives To File Browser that Work Well With S3
- [Django]-Crispy-forms InlineRadios don't show my model state
- [Django]-Django Oauth Toolkit 2-legged and 3-legged
- [Django]-Django-pipeline 'compressed' is not a valid tag library: ImportError raised loading pipeline.templatetags.compressed: No module named conf
0👍
You can use default
like so:
date = models.DateField(_("Date"), default="{{"+datetime.date.today+"}}")
- [Django]-Make celery wait for task to finish
- [Django]-How to run django app binded with gunicorn?
- [Django]-Mercurial: Exclude django settings.py after intitial commit
- [Django]-Django settings based on IP or hostname
- [Django]-Python model inheritance and order of model declaration
0👍
You can just add
`<script>
window.onload = function(){
document.getElementById("id_dob").type = "date";
}
</script>`
in the end of your .html file and you can collect date and time as string
Source:stackexchange.com