动态url加载

url:

from django.conf.urls import url

from myApp import views

urlpatterns = [
    # url(r'^time/plus/(\d+)/$', views.hours_ahead),
    url(r'^time/plus/(\d{1,2})/$', views.hours_ahead),

views:

# coding=utf-8
import datetime

from django.http import HttpResponse, Http404


def hours_ahead(request, offset):
    try:
        offset = int(offset)
    except ValueError:
        raise Exception("............")
    dt = datetime.datetime.now() + datetime.timedelta(hours=offset)
    html = "In %s hour(s), it will be %s." % (offset, dt)
    return HttpResponse(html)

 

posted @ 2021-07-01 14:18  半日闲1  阅读(76)  评论(0编辑  收藏  举报