[Answered ]-Django show template based on date

2👍

That’s easy, in your views.py you just do an if else block:

from django.shortcuts import render

def alphabet_view(request):
    if day == 'Monday':
        return render(request, 'a.html', {..context..})
    elif day == 'Tuesday':
        return render( request, 'b.html', {......})

view_func has only one url, but you could return whichever template you want based on the logic.

Edit:

Once again, you should refer to django doc. According to your comment, you should define you url like so:

from django.conf.urls import url
from . import views

urlpatterns = [
    url(r'^alphabet/$', views.alphabet_view, name='alphabet'),
]

Leave a comment