from django.http import HttpResponse
import datetime
def root(request):
return HttpResponse("Hi, I'm root.")
def hello(request):
return HttpResponse("Hello world!")
def current_datetime(request):
now = datetime.datetime.now()
html = '<html><body>It is now %s.</body></html>' % now
return HttpResponse(html)
def hours_ahead(request, offset):
try:
offset = int(offset)
except ValueError:
raise Http404()
dt = datetime.datetime.now() + datetime.timedelta(hours=offset)
html = '<html><body>In %s hour(s), it will be %s.</body></html>' % (offset, dt)
return HttpResponse(html)
from django.conf.urls import url
from mypro.views import hello, root, current_datetime, hours_ahead
urlpatterns = [
url(r'^$', root),
url(r'^hello/$', hello),
url(r'^time/$', current_datetime),
url(r'^time/plus/(\d{1,2})/$', hours_ahead),
]
loose coupling is a software-development approach that values the importance
of making pieces interchangeable. If two pieces of code are loosely coupled,
then changes made to one of the pieces will have little or no effect on the
other.