ROOT_URLCONF decides the python file for routing
ROOT_URLCONF is urls.py by default
when a request comes in, Django loads ROOT_URLCONF and find the match between request url & urlpatterns
when pattern found, the associated view function is called( the function is passed HttpRequest object as first parameter)
the view function will return an HttpResponse object
define urlpatterns
ex:
urlpatterns = patterns( '', ( r'^test/$', testFunction) )
match /test/ , if request is /test/, testFunction is called
define view function:
ex:
def test(request):
now=datetime.datetime.now()
html= "<html><body>It is now %s.</body></html>" % now
return HttpResponse(html)
沒有留言:
張貼留言