0

I have a workspace where users can add note, they can pick a date I am trying to create 2 links, one for yesterday, one for tomorrow.

Right now I am using a calendar and it is fine, but I would like to create 2 quick links that send them to the note for yesterday.

So i have a code like that :

def WorkspaceYesterday(request):

yesterday = datetime.now() - timedelta(days=1)
yesterday.strftime('%m%d%y')

But i dont know how to render it in my template with a link.

Thank you

  • assign it to variable and send it as parameter to template. ie. `render(request, 'index.html', {'yesterday': yesterday.strftime('%m%d%y')})` – furas Dec 07 '19 at 02:53

1 Answers1

0
# you just need to render the context 'yesterday' to your template from your function

from django.shortcuts import render

def WorkspaceYesterday(request):
    yesterday = datetime.now() - timedelta(days=1)
    yesterday = yesterday.strftime('%m%d%y')
    render(request, 'index.html', {'yesterday': yesterday})



# In your template index.html

<p>{{ yesterday }}</p>
Mukul Kumar
  • 2,033
  • 1
  • 7
  • 14