Django: hello world!

  • 1 Creating a new project: mypro
$ django-admin startproject mypro
mypro
├── manage.py
└── mypro
    ├── __init__.py
    ├── settings.py
    ├── urls.py
    └── wsgi.py
  • 2 coding...

in views.py,

from django.http import HttpResponse

def root(request):
    return HttpResponse("Hi, I'm root.")

def hello(request):
    return HttpResponse("Hello world!")

in urls.py,

from django.conf.urls import url

from mypro.views import hello, root

urlpatterns = [
    url(r'^$', root),
    url(r'^hello/$', hello),
]
  • 3 running...
$ python manage.py runserver
Django: hello world!_第1张图片
root
Django: hello world!_第2张图片
hello world

read more

  • The django Book: Django Views and URLconfs

  • Python documentation: re

  • Django documentation: URL dispatcher

你可能感兴趣的:(Django: hello world!)