Django development

本文详细介绍使用Django 0.9.6版本创建项目的步骤,包括环境配置、项目及应用创建、数据库设置等,并演示如何通过命令行操作实现数据库表的创建。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Django integrated to mod_python

1.download django-0.9.6
2.uncompress then run: python setup.py install
3.Add the python/Scripts to env path
4.Add the .py to the PATHEXE
So far,you can set up a project.
Steps:
1.create a directory in c:/mysite
2.django-admin.py startproject mysite
Setup an application (polls)
1.c:\mysite>python mysite\manage.py startapp polls
2.modify the 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()
   
   
3.edit the setting.py
   .configure the database connection
   .modify below:
      INSTALLED_APPS = (
       'django.contrib.auth',
       'django.contrib.contenttypes',
       'django.contrib.sessions',
       'django.contrib.sites',
       'mysite.polls'
       )
4.execute the command then create the schema in mysql
  c:\mysite>python mysite/manage.py sql polls   
  success,you can see below:
  BEGIN;
 CREATE TABLE "polls_poll" (
     "id" serial NOT NULL PRIMARY KEY,
     "question" varchar(200) NOT NULL,
     "pub_date" timestamp with time zone NOT NULL
 );
 CREATE TABLE "polls_choice" (
     "id" serial NOT NULL PRIMARY KEY,
     "poll_id" integer NOT NULL REFERENCES "polls_poll" ("id"),
     "choice" varchar(200) NOT NULL,
     "votes" integer NOT NULL
 );
 COMMIT;   
 
 
5.Create the table and session
  c:\mysite>python mysite/manage.py syncdb
 
6.python mysite/manage.py shell
   
  >>>from mysite.polls.models import Poll, Choice
  >>>Poll.objects.all()
  >>>Poll.objects.filter(id=1)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值