|
/Coding/python/Django:
Django "Hello World" Example
(Lifted from [1].)
On my Debian system, first install Django:
apt-get install python-djangocd to where you want to put your new Django web application, and create a Django project:
django-admin.py startproject djangoHellowhich will cause a subdirectory djangoHello to be created, containing manage.py, settings.py, and urls.py, among other things. Now create an application within that project:
cd djangoHellowhich will create a helloworld subdirectory, containing models.py and views.py. Now edit djangoHello/helloworld/views.py to add the following lines:
python manage.py startapp helloworld
Now edit djangoHello/urls.py, and add the line below after the line above (that will already be in the file):from django.http import HttpResponse def helloworld(request): return HttpResponse('Hello, World!')
#(r'^admin/(.*)', admin.site.root),Make sure you are in the project root directory (djangoHello) and start the built-in Django server:
(r'^$', 'djangoHello.helloworld.views.helloworld'),
python manage.py runserver 0.0.0.0:8000and point your browser at port 8000 (localhost:8000 if browser and Django are on the same machine) and observer your "Hello, World!".
[1] https://support.eapps.com/index.php?_m=knowledgebase&_a=viewarticle&kbarticleid=178
posted at: 05:01 | path: /Coding/python/Django | permanent link to this entry