Internet & Web Application

Django Note

Django : Python WebApp Framework

– Download & Install Django by
> python install

Basic run-able Django WebApp

– Create project directory
> startproject <project name>

– Go into <project name> directory
> cd <project name>

  • An empty file that tells Python that this directory should be considered a Python package. (Read more about packages in the official Python docs if you're a Python beginner.)
  • A command-line utility that lets you interact with this Django project in various ways. You can read all the details about in and
  • Settings/configuration for this Django project. Django settings will tell you all about how settings work.
  • The URL declarations for this Django project; a “table of contents” of your Django-powered site. You can read more about URLs in URL dispatcher.

– Test server, 1st run-time
> python runserver

Database system initialization

– Database setup , in
see information here ..

*** if you’re using ‘MySQL’ database engine, please create ‘database name’ as you’ve set in ‘’.

– To make database complete with ‘database table’ that be need by ‘django app’ ..
> python syncdb

The result is =>

MVC model in Django

– Model in Django’s called => ‘Model’

– View in Django’s called => ‘Template’

– Controller in Django’s called => ‘View’

To ignore confussion, you should say that django is ‘MTV model’.

Create models (database interface)

– create app
> python startapp polls

… A project is a collection of configuration and apps for a particular Web site …

– First thing to do, is to define ‘Model’ .. look in polls/ .. edit them to

… The goal is to define your data model in one place and automatically derive things from it.

– to activating models .. tell our project , ‘polls’ , is installed .. edit

– then ..
> python sql polls
SQL command for tables creation ‘re automatically generated …

If you’re interested, also run the following commands:

  • python validate — Checks for any errors in the construction of your models.
  • python sqlcustom polls — Outputs any custom SQL statements (such as table modifications or constraints) that are defined for the application.
  • python sqlclear polls — Outputs the necessary DROP TABLE statements for this app, according to which tables already exist in your database (if any).
  • python sqlindexes polls — Outputs the CREATE INDEX statements for this app.
  • python sqlall polls — A combination of all the SQL from the sql, sqlcustom, and sqlindexes commands.

– make tables
> python syncdb

Read the documentation for full information on what the utility can do.



Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  เปลี่ยนแปลง )

Google+ photo

You are commenting using your Google+ account. Log Out /  เปลี่ยนแปลง )

Twitter picture

You are commenting using your Twitter account. Log Out /  เปลี่ยนแปลง )

Facebook photo

You are commenting using your Facebook account. Log Out /  เปลี่ยนแปลง )


Connecting to %s