i think you need to replace:
form = UserQueryForm()
with
form = UserQueryForm(initial={'date': date})
See: https://docs.djangoproject.com/en/2.0/ref/forms/api/
Etienne
Le 2018-02-19 à 10:31, prince gosavi a écrit :
|
# my_app/views.py
fromdjango.shortcuts importrender,get_object_or_404
# Create your views here.
from.models importUser
from.forms importUserQueryForm
defhome(request):# home page
a_list =User.objects.filter()
foritem ina_list:
context
={'username':item.username,'contact_info':item.mobile_nos,'req_date':item.request_date}
print(item.username)
returnrender(request,'userinfo/information.html',context)
defquery_form(request):# the concerned view
ifrequest.method =='POST':
form =UserQueryForm(request.POST)
ifform.is_valid():
get_date =request.POST['date']
get_username =request.POST['username']
get_mobile_nos =request.POST['mobilenos']
context
={'username':get_username,'contact_info':get_mobile_nos,'req_date':get_datetime}
returnrender(request,'userinfo/information.html',context)
else:
form =UserQueryForm()
returnrender(request,'userinfo/form.html',{'form':form })
|
On Monday, February 19, 2018 at 7:52:05 PM UTC+5:30, prince gosavi wrote:
Hi,
I am building a simple django application for user feedback. And I
have created a form for that purpose.
Here is the snippet:
|
# my_app/forms.py
fromdjango importforms
importdatetime
classUserQueryForm(forms.Form):
date =forms.DateField(initial=datetime.date.today)# need help
username =forms.CharField(label='Username:',max_length=15)
mobilenos =forms.CharField(max_length=10,label='Mobile Nos')
|
And here is my template:
|
<!--my_app/templates/my_app/form.html-->
<formaction=""method="POST">
{% csrf_token %}
<h1>Date:</h1>
{{ form.date }}
{{ form.username.label}}
{{ form.username }}
<br/>
{{ form.mobilenos.label}}
{{ form.mobilenos}}
<br/>
<inputtype="submit"value="Submit">
</form>
|
I would like to initialize the *date *so that it is automatically
set to today's date when the page loads.
All suggestions are welcomed.
Regards,
Rajkumar
On Monday, February 19, 2018 at 7:52:05 PM UTC+5:30, prince gosavi wrote:
Hi,
I am building a simple django application for user feedback. And I
have created a form for that purpose.
Here is the snippet:
|
# my_app/forms.py
fromdjango importforms
importdatetime
classUserQueryForm(forms.Form):
date =forms.DateField(initial=datetime.date.today)# need help
username =forms.CharField(label='Username:',max_length=15)
mobilenos =forms.CharField(max_length=10,label='Mobile Nos')
|
And here is my template:
|
<!--my_app/templates/my_app/form.html-->
<formaction=""method="POST">
{% csrf_token %}
<h1>Date:</h1>
{{ form.date }}
{{ form.username.label}}
{{ form.username }}
<br/>
{{ form.mobilenos.label}}
{{ form.mobilenos}}
<br/>
<inputtype="submit"value="Submit">
</form>
|
I would like to initialize the *date *so that it is automatically
set to today's date when the page loads.
All suggestions are welcomed.
Regards,
Rajkumar
On Monday, February 19, 2018 at 7:52:05 PM UTC+5:30, prince gosavi wrote:
Hi,
I am building a simple django application for user feedback. And I
have created a form for that purpose.
Here is the snippet:
|
# my_app/forms.py
fromdjango importforms
importdatetime
classUserQueryForm(forms.Form):
date =forms.DateField(initial=datetime.date.today)# need help
username =forms.CharField(label='Username:',max_length=15)
mobilenos =forms.CharField(max_length=10,label='Mobile Nos')
|
And here is my template:
|
<!--my_app/templates/my_app/form.html-->
<formaction=""method="POST">
{% csrf_token %}
<h1>Date:</h1>
{{ form.date }}
{{ form.username.label}}
{{ form.username }}
<br/>
{{ form.mobilenos.label}}
{{ form.mobilenos}}
<br/>
<inputtype="submit"value="Submit">
</form>
|
I would like to initialize the *date *so that it is automatically
set to today's date when the page loads.
All suggestions are welcomed.
Regards,
Rajkumar
On Monday, February 19, 2018 at 7:52:05 PM UTC+5:30, prince gosavi wrote:
Hi,
I am building a simple django application for user feedback. And I
have created a form for that purpose.
Here is the snippet:
|
# my_app/forms.py
fromdjango importforms
importdatetime
classUserQueryForm(forms.Form):
date =forms.DateField(initial=datetime.date.today)# need help
username =forms.CharField(label='Username:',max_length=15)
mobilenos =forms.CharField(max_length=10,label='Mobile Nos')
|
And here is my template:
|
<!--my_app/templates/my_app/form.html-->
<formaction=""method="POST">
{% csrf_token %}
<h1>Date:</h1>
{{ form.date }}
{{ form.username.label}}
{{ form.username }}
<br/>
{{ form.mobilenos.label}}
{{ form.mobilenos}}
<br/>
<inputtype="submit"value="Submit">
</form>
|
I would like to initialize the *date *so that it is automatically
set to today's date when the page loads.
All suggestions are welcomed.
Regards,
Rajkumar
On Monday, February 19, 2018 at 7:52:05 PM UTC+5:30, prince gosavi wrote:
Hi,
I am building a simple django application for user feedback. And I
have created a form for that purpose.
Here is the snippet:
|
# my_app/forms.py
fromdjango importforms
importdatetime
classUserQueryForm(forms.Form):
date =forms.DateField(initial=datetime.date.today)# need help
username =forms.CharField(label='Username:',max_length=15)
mobilenos =forms.CharField(max_length=10,label='Mobile Nos')
|
And here is my template:
|
<!--my_app/templates/my_app/form.html-->
<formaction=""method="POST">
{% csrf_token %}
<h1>Date:</h1>
{{ form.date }}
{{ form.username.label}}
{{ form.username }}
<br/>
{{ form.mobilenos.label}}
{{ form.mobilenos}}
<br/>
<inputtype="submit"value="Submit">
</form>
|
I would like to initialize the *date *so that it is automatically
set to today's date when the page loads.
All suggestions are welcomed.
Regards,
Rajkumar
--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected]
<mailto:[email protected]>.
To post to this group, send email to [email protected]
<mailto:[email protected]>.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/e4f14993-12fc-4314-b456-155dbd876772%40googlegroups.com
<https://groups.google.com/d/msgid/django-users/e4f14993-12fc-4314-b456-155dbd876772%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
Etienne Robillard
[email protected]
https://www.isotopesoftware.ca/
--
You received this message because you are subscribed to the Google Groups "Django
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/5608f3f8-abca-879c-08c1-e78b4f4b85ce%40yandex.com.
For more options, visit https://groups.google.com/d/optout.