-
Notifications
You must be signed in to change notification settings - Fork 202
Expand file tree
/
Copy pathviews.py
More file actions
50 lines (37 loc) · 1.34 KB
/
views.py
File metadata and controls
50 lines (37 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from django.shortcuts import redirect, render
from django.utils.timezone import datetime
from django.views.generic import ListView
from hello.forms import LogMessageForm
from hello.models import LogMessage
class HomeListView(ListView):
"""Renders the home page, with a list of all polls."""
model = LogMessage
def get_context_data(self, **kwargs):
context = super(HomeListView, self).get_context_data(**kwargs)
return context
def about(request):
"""Renders the about page."""
return render(request, "hello/about.html")
def contact(request):
"""Renders the contact page."""
return render(request, "hello/contact.html")
def hello_there(request, name):
"""Renders the hello_there page.
Args:
name: Name to say hello to
"""
return render(
request, "hello/hello_there.html", {"name": name, "date": datetime.now()}
)
def log_message(request):
form = LogMessageForm(request.POST or None)
if request.method == "POST":
if form.is_valid():
message = form.save(commit=False)
message.log_date = datetime.now()
message.save()
return redirect("home")
else:
return render(request, "hello/log_message.html", {"form": form})
else:
return render(request, "hello/log_message.html", {"form": form})