部署好环境之后,要开发一个web程序,首先我们要建立一个项目:
django-admin.py startproject mysite
├── manage.py └── mysite ├── __init__.py ├── settings.py ├── urls.py └── wsgi.py
mysite/__init__.py:是项目的初始文件,一开始是一个空的文件;
mysite/settings.py:是项目的配置文件 ,如数据库连接、模板地址等;
mysite/urls.py:是项目的url映射文件,可以指定哪些url由哪些module来处理,类似于apache的httpd.conf文件;
mysite/wsgi.py:python的web服务器网关服务中间件。
python manage.py runserver 127.0.0.1:8080
It worked! Congratulations on your first Django-powered page. Of course, you haven't actually done any work yet. Here's what to do next: If you plan to use a database, edit the DATABASES setting in mysite1/settings.py. Start your first app by running python manage.py startapp [appname]. You're seeing this message because you have DEBUG = True in your Django settings file and you haven't configured any URLs. Get to work!
from django.http import HttpResponse def hello(request): return HttpResponse("hello world")
from django.conf.urls import patterns, include, url # Uncomment the next two lines to enable the admin: # from django.contrib import admin # admin.autodiscover() urlpatterns = patterns('', # Examples: # url(r'^$', 'mysite1.views.home', name='home'), # url(r'^mysite1/', include('mysite1.foo.urls')), # Uncomment the admin/doc line below to enable admin documentation: # url(r'^admin/doc/', include('django.contrib.admindocs.urls')), # Uncomment the next line to enable the admin: # url(r'^admin/', include(admin.site.urls)), url(r'^hello/', 'mysite1.views.hello',name='hello'), )