Differences between revisions 1 and 2
Revision 1 as of 2005-07-20 02:02:01
Size: 10758
Editor: limodou
Comment:
Revision 2 as of 2009-12-25 07:19:09
Size: 10818
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
::-- limodou [[[DateTime(2005-07-20T02:02:01Z)]]]
[[TableOfContents]]
::-- limodou [<<DateTime(2005-07-20T02:02:01Z)>>]
<<TableOfContents>>
Line 13: Line 13:
Django would not be possible without a whole host of open-source projects -- [http://httpd.apache.org/ Apache], [http://www.python.org/ Python], and [http://www.postgresql.org/ PostgreSQL] to name a few -- and we're thrilled to be able to give something back to the open-source community. Django would not be possible without a whole host of open-source projects -- [[http://httpd.apache.org/|Apache]], [[http://www.python.org/|Python]], and [[http://www.postgresql.org/|PostgreSQL]] to name a few -- and we're thrilled to be able to give something back to the open-source community.
Line 17: Line 17:
Django is named after [http://en.wikipedia.org/wiki/Django_Reinhardt Django Reinhardt], a gypsy jazz guitarist from the 1930s to early 1950s. To this day, he's considered one of the best guitarists of all time. Django is named after [[http://en.wikipedia.org/wiki/Django_Reinhardt|Django Reinhardt]], a gypsy jazz guitarist from the 1930s to early 1950s. To this day, he's considered one of the best guitarists of all time.
Line 21: Line 21:
According to [http://en.wikipedia.org/wiki/Django_Reinhardt Wikipedia], "Django is pronounced '''zhane''-go (with a long 'a')." According to [[http://en.wikipedia.org/wiki/Django_Reinhardt|Wikipedia]], "Django is pronounced '''zhane''-go (with a long 'a')."
Line 29: Line 29:
Yes. Compared to development time, hardware is cheap, and so Django is designed to take advantage of as much hardware as you can throw at it. Django ships with clean separation of the database layer from the application layer and a simple-yet-powerful [http://www.djangoproject.com/documentation/cache/ cache framework]. Yes. Compared to development time, hardware is cheap, and so Django is designed to take advantage of as much hardware as you can throw at it. Django ships with clean separation of the database layer from the application layer and a simple-yet-powerful [[http://www.djangoproject.com/documentation/cache/|cache framework]].
Line 33: Line 33:
Django was developed at [http://code.djangoproject.com/wiki/WorldOnline World Online], the Web department of a newspaper in Lawrence, Kansas, USA. Django was developed at [[http://code.djangoproject.com/wiki/WorldOnline|World Online]], the Web department of a newspaper in Lawrence, Kansas, USA.
Line 36: Line 36:
  [http://www.holovaty.com/ Adrian Holovaty]   [[http://www.holovaty.com/|Adrian Holovaty]]
Line 38: Line 38:
  Adrian is a gypsy-jazz virtuoso, an amateur Beatles historian and a proud Chicagoan. He's also a pretty decent programmer, with a knack for whipping data into shape and putting it to work for the good of his fellow man. Adrian is the lead developer at World Online and the man behind the code at [http://www.chicagocrime.org/ chicagocrime.org]. He lives in Chicago.   Adrian is a gypsy-jazz virtuoso, an amateur Beatles historian and a proud Chicagoan. He's also a pretty decent programmer, with a knack for whipping data into shape and putting it to work for the good of his fellow man. Adrian is the lead developer at World Online and the man behind the code at [[http://www.chicagocrime.org/|chicagocrime.org]]. He lives in Chicago.
Line 40: Line 40:
  [http://simon.incutio.com/ Simon Willison]   [[http://simon.incutio.com/|Simon Willison]]
Line 44: Line 44:
  [http://www.jacobian.org/ Jacob Kaplan-Moss]   [[http://www.jacobian.org/|Jacob Kaplan-Moss]]
Line 48: Line 48:
  [http://www.wilsonminer.com/live/ Wilson Miner]   [[http://www.wilsonminer.com/live/|Wilson Miner]]
Line 69: Line 69:
     1. [http://www.djangoproject.com/download/ Download the code].      1. [[http://www.djangoproject.com/download/|Download the code]].
Line 71: Line 71:
     1. Install Django (read the [http://www.djangoproject.com/documentation/install/ installation guide]).      1. Install Django (read the [[http://www.djangoproject.com/documentation/install/|installation guide]]).
Line 73: Line 73:
     1. Walk through the [http://www.djangoproject.com/documentation/tutorial1/ tutorial].      1. Walk through the [[http://www.djangoproject.com/documentation/tutorial1/|tutorial]].
Line 75: Line 75:
     1. Check out the rest of the [http://www.djangoproject.com/documentation/ documentation], and [http://www.djangoproject.com/community/ ask questions] if you run into trouble.      1. Check out the rest of the [[http://www.djangoproject.com/documentation/|documentation]], and [[http://www.djangoproject.com/community/|ask questions]] if you run into trouble.
Line 85: Line 85:
Django requires [http://www.python.org/ Python] 2.3 or later. Django requires [[http://www.python.org/|Python]] 2.3 or later.
Line 87: Line 87:
For a development environment -- if you just want to experiment with Django -- you don't need to have a separate Web server installed; Django comes with its own lightweight development server. For a production environment, we recommend [http://httpd.apache.org/ Apache 2] and [http://www.modpython.org/ mod_python], although Django follows the [http://www.python.org/peps/pep-0333.html WSGI] spec, which means it can run on a variety of server platforms. For a development environment -- if you just want to experiment with Django -- you don't need to have a separate Web server installed; Django comes with its own lightweight development server. For a production environment, we recommend [[http://httpd.apache.org/|Apache 2]] and [[http://www.modpython.org/|mod_python]], although Django follows the [[http://www.python.org/peps/pep-0333.html|WSGI]] spec, which means it can run on a variety of server platforms.
Line 89: Line 89:
You'll also need a database engine. [http://www.postgresql.org/ PostgreSQL] is recommended, and [http://www.mysql.com/ MySQL] is supported. You'll also need a database engine. [[http://www.postgresql.org/|PostgreSQL]] is recommended, and [[http://www.mysql.com/|MySQL]] is supported.
Line 97: Line 97:
However, if you don't want to use mod_python, you can use a different server, as long as that server has [http://www.python.org/peps/pep-0333.html WSGI] hooks. More information on alternate server arrangements is forthcoming. However, if you don't want to use mod_python, you can use a different server, as long as that server has [[http://www.python.org/peps/pep-0333.html|WSGI]] hooks. More information on alternate server arrangements is forthcoming.
Line 102: Line 102:
   * For Python 2.4, check out this [http://www.lehuen.com/nicolas/index.php/2005/02/21/39-win32-build-of-mod_python-314-for-python-24 guide to mod_python & Python 2.3].    * For Python 2.4, check out this [[http://www.lehuen.com/nicolas/index.php/2005/02/21/39-win32-build-of-mod_python-314-for-python-24|guide to mod_python & Python 2.3]].
Line 104: Line 104:
   * For Python 2.3, grab mod_python from [http://www.mod_python.org/ http://www.mod_python.org/] and read [http://groups-beta.google.com/group/comp.lang.python/msg/139af8c83a5a9d4f Running mod_python on Apache on Windows2000].    * For Python 2.3, grab mod_python from [[http://www.mod_python.org/|http://www.mod_python.org/]] and read [[http://groups-beta.google.com/group/comp.lang.python/msg/139af8c83a5a9d4f|Running mod_python on Apache on Windows2000]].
Line 106: Line 106:
   * Also, try this (not Windows-specific) [http://www.dscpl.com.au/articles/modpython-001.html guide to getting mod_python working].    * Also, try this (not Windows-specific) [[http://www.dscpl.com.au/articles/modpython-001.html|guide to getting mod_python working]].
Line 175: Line 175:
   * Set the REGISTRATION_COOKIE_DOMAIN setting to match your domain. For example, if you're going to "[http://www.mysite.com/admin/ http://www.mysite.com/admin/]" in your browser, set REGISTRATION_COOKIE_DOMAIN = 'www.mysite.com'.    * Set the REGISTRATION_COOKIE_DOMAIN setting to match your domain. For example, if you're going to "[[http://www.mysite.com/admin/|http://www.mysite.com/admin/]]" in your browser, set REGISTRATION_COOKIE_DOMAIN = 'www.mysite.com'.
Line 186: Line 186:
We think it's very purty, but if you don't agree, you can modify the admin site's presentation by editing the CSS stylesheet and/or associated image files. The site is built using semantic HTML, so any changes you'd like to make should be possible by editing the CSS stylesheet. We've got a [http://www.djangoproject.com/documentation/admin_css/ guide to the CSS used in the admin] to get you started. We think it's very purty, but if you don't agree, you can modify the admin site's presentation by editing the CSS stylesheet and/or associated image files. The site is built using semantic HTML, so any changes you'd like to make should be possible by editing the CSS stylesheet. We've got a [[http://www.djangoproject.com/documentation/admin_css/|guide to the CSS used in the admin]] to get you started.

::-- limodou [2005-07-20 02:02:01]

Django FAQ

General questions

Why does this project exist?

Django grew from a very practical need: in our fast-paced newsroom, we often have only a matter of hours to take a complicated Web application from concept to public launch. Django was designed to not only allow us to build Web applications quickly, but to allow us to build them right.

Django would not be possible without a whole host of open-source projects -- Apache, Python, and PostgreSQL to name a few -- and we're thrilled to be able to give something back to the open-source community.

What does "Django" mean, and how do you pronounce it?

Django is named after Django Reinhardt, a gypsy jazz guitarist from the 1930s to early 1950s. To this day, he's considered one of the best guitarists of all time.

Listen to his music. You'll like it.

According to Wikipedia, "Django is pronounced zhane-go (with a long 'a')."

Is Django stable?

We've been using Django for almost two years. Sites built on Django have weathered traffic spikes of over one million hits an hour, and at least one Slashdotting. Yes, it's quite stable.

Does Django scale?

Yes. Compared to development time, hardware is cheap, and so Django is designed to take advantage of as much hardware as you can throw at it. Django ships with clean separation of the database layer from the application layer and a simple-yet-powerful cache framework.

Who's behind this?

Django was developed at World Online, the Web department of a newspaper in Lawrence, Kansas, USA.

  • Adrian Holovaty

    Adrian is a gypsy-jazz virtuoso, an amateur Beatles historian and a proud Chicagoan. He's also a pretty decent programmer, with a knack for whipping data into shape and putting it to work for the good of his fellow man. Adrian is the lead developer at World Online and the man behind the code at chicagocrime.org. He lives in Chicago.

    Simon Willison Simon is a well-respected Web developer from England. He had a one-year internship at World Online, during which time he and Adrian developed Django from scratch. He's enthusiastic, he's passionate about best practices in Web development, and he really likes squirrels. Probably to a fault. He went back to university to finish his degree and is poised to continue doing big, exciting things on the Web. He lives in England.

    Jacob Kaplan-Moss Jacob is a whipper-snapper from California who spends equal time coding and cooking. He does Web development for World Online and actively hacks on various cool side projects. He's contributed to the Python-ObjC bindings and was the first guy to figure out how to write Tivo apps in Python. Lately he's been messing with Python on the PSP. He lives in Lawrence, Kansas.

    Wilson Miner Wilson's design-fu makes us all look like rock stars. When not sneaking into apartment complex swimming pools he is the Commercial Development Director for World Online, which means he makes the money that pays all our paychecks. He lives in Lawrence, Kansas.

Django appears to be a MVC framework, but you call the Controller the "view", and the View the "template". How come you don't use the standard names?

That's because Django isn't strictly a MVC framework. We don't really believe in any capital-M Methodologies; we do what "feels" right. If you squint the right way, you can call Django's ORM the "Model", the view functions the "View", and the dynamically-generated API the "Controller" -- but not really.

So, although we've been strongly influenced by MVC -- especially in the separation-of-data-from-logic department -- we've also strayed from the path where it makes sense.

Do you have any of those nifty "screencast" things?

They're in the works. It's amazing how much time those things take! Stay tuned...

Installation questions

How do I get started?

  1. Download the code.

  2. Install Django (read the installation guide).

  3. Walk through the tutorial.

  4. Check out the rest of the documentation, and ask questions if you run into trouble.

How do I fix the "install a later version of setuptools" error?

Just run the ex_setup.py script in the Django distribution.

What are Django's prerequisites?

Django requires Python 2.3 or later.

For a development environment -- if you just want to experiment with Django -- you don't need to have a separate Web server installed; Django comes with its own lightweight development server. For a production environment, we recommend Apache 2 and mod_python, although Django follows the WSGI spec, which means it can run on a variety of server platforms.

You'll also need a database engine. PostgreSQL is recommended, and MySQL is supported.

Do I have to use mod_python?

Not if you just want to play around and develop things on your local computer. Django comes with its own Web server, and things should Just Work.

For production use, though, we recommend mod_python. The Django developers have been running it on mod_python for about two years, and it's quite stable.

However, if you don't want to use mod_python, you can use a different server, as long as that server has WSGI hooks. More information on alternate server arrangements is forthcoming.

How do I install mod_python on Windows?

(Thanks to deelan for this info.)

Will Django run under shared hosting (like TextDrive or Dreamhost)?

Right now, no, unless you can get your host to install mod_python. However, as the community starts to use Django's WSGI bindings with other Web servers, this will probably be possible sooner rather than later.

Using Django

Why do I get an error about importing DJANGO_SETTINGS_MODULE?

Make sure that:

    • The environment variable DJANGO_SETTINGS_MODULE is set to a fully-qualified Python module (i.e. "mysite.settings.main").
    • Said module is on sys.path (import mysite.settings.main should work).
    • The module doesn't contain syntax errors (of course).
    • If you're using mod_python but not using Django's request handler, you'll need to work around a mod_python bug related to the use of SetEnv; before you import anything from Django you'll need to do the following:

      os.environ.update(req.subprocess_env)
      (where req is the mod_python request object).

I can't stand your template language. Do I have to use it?

We happen to think our template engine is the best thing since chunky bacon, but we recognize that choosing a template language runs close to religion. There's nothing about Django that requires using the template language, so if you're attached to ZPT, Cheetah, or whatever, feel free to use those.

The database API

How can I see the raw SQL queries Django is running?

Make sure your Django DEBUG setting is set to True. Then, just do this:

>>> from django.core.db import db
>>> db.queries
[{'sql': 'SELECT polls_polls.id,polls_polls.question,polls_polls.pub_date FROM polls_polls',
'time': '0.002'}]

db.queries is only available if DEBUG is True. It's a list of dictionaries in order of query execution. Each dictionary has the following:

``sql`` -- The raw SQL statement
``time`` -- How long the statement took to execute, in seconds.

The admin site

I can't log in. When I enter a valid username and password, it just brings up the login page again, with no error messages.

The login cookie isn't being set correctly, because the domain of the cookie sent out by Django doesn't match the domain in your browser. Try these two things:

  • Set the REGISTRATION_COOKIE_DOMAIN setting to match your domain. For example, if you're going to "http://www.mysite.com/admin/" in your browser, set REGISTRATION_COOKIE_DOMAIN = 'www.mysite.com'.

  • Some browsers (Firefox?) don't like to accept cookies from domains that don't have dots in them. If you're running the admin site on "localhost" or another domain that doesn't have a dot in it, try going to "localhost.localdomain" or "127.0.0.1". And set REGISTRATION_COOKIE_DOMAIN accordingly.

I can't log in. When I enter a valid username and password, it brings up the login page again, with a "Please enter a correct username and password" error.

If you're sure your username and password are correct, make sure your user account has is_active and is_staff set to True. The admin site only allows access to users with those two fields both set to True.

The dynamically-generated admin site is ugly! How can I change it?

We think it's very purty, but if you don't agree, you can modify the admin site's presentation by editing the CSS stylesheet and/or associated image files. The site is built using semantic HTML, so any changes you'd like to make should be possible by editing the CSS stylesheet. We've got a guide to the CSS used in the admin to get you started.

DjangoFaq (last edited 2009-12-25 07:19:09 by localhost)