Depending on the weekday, I want the page to show either Monday, Tuesday, Wed templates and so forth by recognizing system dates. First, Monday, Tuesday, Wed are updated via admin page and corresponding html pages are shown. Below are the snippets, but there seems to be some error, as it's returning
"didn't return an HttpResponse object. It returned None instead."
For instance for days page,
if today is Monday, it should show monday.html
if today is Tuesday, it should show tuesday.html by recognizing system dates.
urls.py
urlpatterns = patterns('',
url(r'^days/$', views.days_view, name='days'),)
views.py
from datetime import date
from django.shortcuts import render
def days_view(request):
abc = datetime.datetime.today().weekday()
if abc == '1':
return render(request, 'app/monday.html')
elif abc == '2':
return render(request, 'app/tuesday.html')
else:
return HttpResponse('<h1>Page was not found</h1>')
models.py ( tuesday, wed... are same as monday)
class Monday(models.Model):
author = models.ForeignKey(User, null=True, blank=True, editable=False)
title = models.CharField(max_length=300)
text = models.TextField()
created_date = models.DateTimeField(
default=timezone.now)
published_date = models.DateTimeField(
blank=True, null=True, default=timezone.now)
def publish(self):
self.published_date = timezone.now()
self.save()
def __str__(self):
return self.title
Monday.html
{% for monday in mondays %}
<td><h5>{{ monday.title }}</h5></td>
<td><h5>{{ monday.text }}</h5></td>