网上的Django资料太乱了,我想写一下自己的学习过程(只记大体过程,有时间就完善)。(用eclipse+PyDev工具开发的)
1、项目结构
2、关键代码:(注意缩进,可能贴上来缩进格式等有变化,我不一一改了)
blog.views.py:
from django.shortcuts import render
from django.http import HttpResponse
def index(req):
return HttpResponse('<center>hello ,Django !</center>')
pj01.urls.py
urlpatterns = patterns('',
url(r'^blog/index/$','blog.views.index'),
)
pj01.settings.py
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'blog',
)
3、运行测试:http://127.0.0.1/blog/index