Answer the question
In order to leave comments, you need to log in
Dynamic urls not working in Django?
Reading Django book, doing an example from this page
https://rtfm.co.ua/django-book-trete-predstavlenie...
Here is my urls.py
from django.conf.urls import url
from django.contrib import admin
from views import hours_ahead
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^time/plus/d+/$', hours_ahead),
]
from django.http import HttpResponse
import datetime
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)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question