Creating Simple Hello World Django/python web application
# Download the Django from: https://www.djangoproject.com/download/
# untar the application tar
$ tar xvf Django-1.5.2.tar
$ cd Django-1.5.2
# Setup django
$ python setup.py install
- this will install django web framework
# Create the new site using following command
$ django-admin.py startproject mysite
- after you run this command, it will create the following folder structure
- mysite
--- manage.py
--- mysite
------ urls.py
------ __init__.py
------ wsgi.py
------ settings.py
------ views.py (add new file as shown below)
# Create new python file in mysite/ directory as views.py and add following line
#!/usr/bin/python
from django.http import HttpResponse
def hello(request):
html = "<html><body><b>Hello World!</b></body></html>"
return HttpResponse(html)
# Update the urls.py file in mysite/ directory as
#!/usr/bin/python
from django.conf.urls import patterns, include, url
from mysite.views import hello
urlpatterns = patterns('',
url(r'^$', hello),
)
# Finally from inside mysite/ directory run this command
$ python manage.py runserver
# Open the browser and type this url http://localhost:8000
# Download the Django from: https://www.djangoproject.com/download/
# untar the application tar
$ tar xvf Django-1.5.2.tar
$ cd Django-1.5.2
# Setup django
$ python setup.py install
- this will install django web framework
# Create the new site using following command
$ django-admin.py startproject mysite
- after you run this command, it will create the following folder structure
- mysite
--- manage.py
--- mysite
------ urls.py
------ __init__.py
------ wsgi.py
------ settings.py
------ views.py (add new file as shown below)
# Create new python file in mysite/ directory as views.py and add following line
#!/usr/bin/python
from django.http import HttpResponse
def hello(request):
html = "<html><body><b>Hello World!</b></body></html>"
return HttpResponse(html)
# Update the urls.py file in mysite/ directory as
#!/usr/bin/python
from django.conf.urls import patterns, include, url
from mysite.views import hello
urlpatterns = patterns('',
url(r'^$', hello),
)
# Finally from inside mysite/ directory run this command
$ python manage.py runserver
# Open the browser and type this url http://localhost:8000
No comments:
Post a Comment