want to take input of datetimefield from my template

40 views
Skip to first unread message

Chander shekhar

unread,
Jul 12, 2020, 1:02:00 PM7/12/20
to Django users
starttime=datetimefield()

i want to take datetimefield from my template but i am not able to do it.
i have created the form and passed the widget of datetime-local but it is not acceptable ,it is giving me error .
Help me to resolve it .
It's important 

Kasper Laudrup

unread,
Jul 12, 2020, 1:07:56 PM7/12/20
to django...@googlegroups.com
It will be a lot easier for people to help you if you share which kind of error you are getting.

Kind regards,

Kasper Laudrup

chander shekhar

unread,
Jul 12, 2020, 1:25:16 PM7/12/20
to django...@googlegroups.com
--
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 django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7D0D33A0-8A01-48F7-9928-A8465CC40066%40stacktrace.dk.
IMG_20200712_185126.jpg

coolguy

unread,
Jul 13, 2020, 2:47:25 PM7/13/20
to Django users
Please share your model, view and template for more clarity. Thanks


On Sunday, July 12, 2020 at 9:25:16 AM UTC-4, Chander shekhar wrote:
On Sun, Jul 12, 2020, 6:37 PM Kasper Laudrup <lau...@stacktrace.dk> wrote:
On July 12, 2020 3:02:00 PM GMT+02:00, Chander shekhar <best...@gmail.com> wrote:
>starttime=datetimefield()
>
>i want to take datetimefield from my template but i am not able to do
>it.
>i have created the form and passed the widget of datetime-local but it
>is
>not acceptable ,it is giving me error .
>Help me to resolve it .
>It's important

It will be a lot easier for people to help you if you share which kind of error you are getting.

Kind regards,

Kasper Laudrup

--
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 django...@googlegroups.com.

chander shekhar

unread,
Jul 13, 2020, 6:08:00 PM7/13/20
to django...@googlegroups.com

#forms.py

class eventform(forms.ModelForm):

 

    class Meta:

        model = Event

        fields = [, 'end_time',]

        widgets = {

    'start_time':  forms.DateTimeInput(attrs={'type''datetime-local'}),

 

Models.py

class Event(models.Model):

    title = models.CharField(max_length=200)

    description = models.TextField()

    start_time = models.DateTimeField()

 views.py

def add(request):

    if request.method=='POST':

        

 

        form=eventform(request.POST)

        if form.is_valid():

            form.save()

            return redirect('calendar')

        else:

            messages.error(request, "Error")

            return render(request,'event/add.html',{'form':form})

template

<form  method='POST' method={% url 'add' %}>

    {% csrf_token %}

 

        {{form.as_p}}

        

     <button class='btn btn-outline-info' type="submit">ADD</button>

 

    </form>

</div>

Regards
Chander Shekhar
(bestcsp)


To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a485f092-32df-42c4-a25b-dc6f1696bbdbo%40googlegroups.com.

chander shekhar

unread,
Jul 13, 2020, 6:09:46 PM7/13/20
to django...@googlegroups.com
it's action not url ,
it's a dummy of my model

Regards
Chander Shekhar
(bestcsp)

Kasper Laudrup

unread,
Jul 13, 2020, 6:27:53 PM7/13/20
to django...@googlegroups.com
Hi Chander,

On 13/07/2020 20.07, chander shekhar wrote:
> #forms.py
>
> classeventform(forms.ModelForm):
>
> classMeta:
>
>         model = Event
>
>         fields = [, 'end_time',]
>
>         widgets = {
>
> 'start_time':  forms.DateTimeInput(attrs={'type': 'datetime-local'}),
>

Look at the format attribute of DateTimeInput:

https://docs.djangoproject.com/en/3.0/ref/forms/widgets/#datetimeinput

and make sure it matches what is being sent by your template. I would
probably test it by just printing out the value of start_time when
submitting the form and go from there.

There might also be some thirdparty Django applications that can help
you. Time is and time formats is a pain to work with.

Kind regards,

Kasper Laudrup

chander shekhar

unread,
Jul 13, 2020, 6:33:14 PM7/13/20
to django...@googlegroups.com
I think here millisecond or microseconds are not coming ,in django-admin it is coming with microseconds

--
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 django-users...@googlegroups.com.

chander shekhar

unread,
Jul 14, 2020, 3:10:32 PM7/14/20
to django...@googlegroups.com
Anyone help me

Kasper Laudrup

unread,
Jul 14, 2020, 5:04:23 PM7/14/20
to django...@googlegroups.com
Hi Chander,

On 14/07/2020 17.08, chander shekhar wrote:
> Anyone help me
>

I did try to give you some advice on something you could do.

Did you try that? How did it work out?

It's very hard for anyone to help you if you're not providing any
information.

Kind regards,

Kasper Laudrup
Reply all
Reply to author
Forward
0 new messages