Sample application in django

i am go to show the current time example


it is easy ........




just create mysite project

(for help ...... just see my link :-   http://letusknowdjango.blogspot.in/2014/09/how-to-create-new-project.html
)




this is tree structure of my project ie., mysite


but we need to create a view page.......... and other are default file....




here the main file is urls.py where wee need to give the url paatern for ..... the page to excute 



let see we will see what are there
and code


 view.py
======


from django.http import HttpResponse
import datetime

def current_datetime(request):
    now = datetime.datetime.now()
    html = "<html><body>It is now %s.</body></html>" % now
    return HttpResponse(html)





urls.py
======


from django.conf.urls import patterns, include, url
from django.contrib import admin
from mysite.view import current_datetime
urlpatterns = patterns('',
 url(r'^time/$', current_datetime),
)




 
to execute the program




but keep in mind the server should in running state...............



that's cool..................



No comments:

Post a Comment