Django

来自开放百科 - 灰狐
(版本间的差异)
跳转到: 导航, 搜索
第15行: 第15行:
 
  python manage.py runserver
 
  python manage.py runserver
 
  http://localhost:8000
 
  http://localhost:8000
 +
 +
创建一个poll应用
 +
python manage.py startapp polls
 +
vi polls/models.py
 +
from django.db import models
 +
 +
class Poll(models.Model):
 +
    question = models.CharField(maxlength=200)
 +
    pub_date = models.DateTimeField('date published')
 +
 +
class Choice(models.Model):
 +
    poll = models.ForeignKey(Poll)
 +
    choice = models.CharField(maxlength=200)
 +
    votes = models.IntegerField()
 +
 +
vi polls/settings.py
 +
INSTALLED_APPS = (
 +
    'django.contrib.auth',
 +
    'django.contrib.contenttypes',
 +
    'django.contrib.sessions',
 +
    'django.contrib.sites',
 +
    'mysite.polls'
 +
)
 +
创建数据库
 +
python manage.py sql polls

2006年9月2日 (六) 11:33的版本

Django: The Web framework for perfectionists with deadlines

安装指南

First, download Django-0.95.tar.gz. Then:

tar xzvf Django-0.95.tar.gz
cd Django-0.95
sudo python setup.py install
cd /var/www
django-admin.py startproject mysite
cd mysite
python manage.py runserver
http://localhost:8000

创建一个poll应用

python manage.py startapp polls
vi polls/models.py
from django.db import models
class Poll(models.Model):
   question = models.CharField(maxlength=200)
   pub_date = models.DateTimeField('date published')
class Choice(models.Model):
   poll = models.ForeignKey(Poll)
   choice = models.CharField(maxlength=200)
   votes = models.IntegerField()
vi polls/settings.py
INSTALLED_APPS = (
   'django.contrib.auth',
   'django.contrib.contenttypes',
   'django.contrib.sessions',
   'django.contrib.sites',
   'mysite.polls'
)

创建数据库

python manage.py sql polls
分享您的观点
个人工具
名字空间

变换
操作
导航
工具箱