download django:
现在需要的版本,如
解压Django-1.3.7.tar.gz:
tar zxvf Django-1.3.7.tar.gz
cd Django-1.3.7
使用root用户调用python命令 安装django到ubuntu:
sudo python setup.py install
if there is no error info,good luck!
测试django 模块是否能正常运行:
>>> import django
>>> if there is no error info ,good luck!测试django自带测试服务器:
python manage.py runserver
正确结果现实如下:
Validating models...
0 errors foundDjango version 1.3.7, using settings 'csvt01.settings'Development server is running at http://127.0.0.1:8000/Quit the server with CONTROL-C.[11/Oct/2015 22:21:17] "GET / HTTP/1.1" 200 2051
目前为止,django-1.3.7 安装基本完成
开始创建django工程:
django-admin.py startproject mysite 创建mysite 工程;
mysite/
__init__.pymanage.pysettings.pyurls.py
设置工程的时区和语言:
vim settings.py
LANGUAGE_CODE = 'zh-cn'
TIME_ZONE = 'Asia/Shanghai'
把即将要实现的应用的名称写到INSTALLED_APPS 元组中:
INSTALLED_APPS = (
'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', 'blog', # Uncomment the next line to enable the admin: # 'django.contrib.admin', # Uncomment the next line to enable admin documentation: # 'django.contrib.admindocs',)修改urls.py(就是 url config文件),指定应用访问路径
vim urls.py like this:
from django.conf.urls.defaults 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'^$', 'csvt01.views.home', name='home'), # url(r'^csvt01/', include('csvt01.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'^blog/index', include(blog.views.index)),)
创建一个应用:
使用django创建一个blog application:
django-admin.py startapp blog
/blog:
__init__.py
models.py
tests.py
views.py
https://docs.python.org/2/tutorial/modules.html