To start a project
see in the computer folder that is /usr/local/bin
there is django-admin.py
so type the command with myfirstdjangoproject
and just follow
so here you need to migrate and runserver
open the browser and try the url
ie., 127.0.0.1:8000
so , i am adding more code to that ......
ie.,
Note:
previously it is mysite project now it is ..... cusat
similarly the view.py is home.py
so do get confused
home.py
======
from django.http import HttpResponse
import datetime
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(request, offset):
offset = int(offset)
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)
urls.py
=====
from django.conf.urls import patterns, include, url
from cusat.home import hello
from cusat.home import current_datetime
from cusat.home import hours
urlpatterns = patterns('',
url(r'^hello/$', hello),
url(r'^time/$', current_datetime),
url(r'^time/plus/(\d{1,2})/$', hours),
)
output
====
here in the url path i am just change 3,1,5,10 and seeing the output
No comments:
Post a Comment