Django development

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)

你可能感兴趣的:(C++,c,mysql,django,python)