2005-07-14 03:08:56 +08:00
==========
Django FAQ
==========
2005-07-15 08:42:28 +08:00
General questions
=================
2005-07-14 03:08:56 +08:00
2005-07-15 08:42:28 +08:00
Why does this project exist?
----------------------------
2006-05-02 09:31:56 +08:00
Django grew from a very practical need: World Online, a newspaper Web
operation, is responsible for building intensive Web applications on journalism
deadlines. In the fast-paced newsroom, World Online often has only a matter of
hours to take a complicated Web application from concept to public launch.
At the same time, the World Online Web developers have consistently been
perfectionists when it comes to following best practices of Web development.
2006-08-24 07:15:09 +08:00
In fall 2003, the World Online developers (Adrian Holovaty and Simon Willison)
ditched PHP and began using Python to develop its Web sites. As they built
intensive, richly interactive sites such as Lawrence.com, they began to extract
a generic Web development framework that let them build Web applications more
and more quickly. They tweaked this framework constantly, adding improvements
over two years.
In summer 2005, World Online decided to open-source the resulting software,
Django. 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.
2005-07-14 03:08:56 +08:00
2005-07-16 03:41:54 +08:00
.. _Apache: http://httpd.apache.org/
.. _Python: http://www.python.org/
.. _PostgreSQL: http://www.postgresql.org/
2005-07-16 01:59:30 +08:00
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.
2005-07-14 03:08:56 +08:00
2006-06-20 10:52:15 +08:00
Django is pronounced **JANG**-oh. Rhymes with FANG-oh. The "D" is silent.
2005-07-14 03:08:56 +08:00
2005-07-16 01:59:30 +08:00
.. _Django Reinhardt: http://en.wikipedia.org/wiki/Django_Reinhardt
2005-07-14 03:08:56 +08:00
Is Django stable?
-----------------
2006-08-24 07:15:09 +08:00
Yes. World Online has been using Django for more than three years. Sites built
on Django have weathered traffic spikes of over one million hits an hour and a
2006-06-20 10:52:15 +08:00
number of Slashdottings. Yes, it's quite stable.
2005-07-14 03:08:56 +08:00
2005-07-15 08:42:28 +08:00
Does Django scale?
------------------
2005-07-16 00:19:53 +08:00
Yes. Compared to development time, hardware is cheap, and so Django is
2005-07-15 08:42:28 +08:00
designed to take advantage of as much hardware as you can throw at it.
2006-05-02 09:31:56 +08:00
Django uses a "shared-nothing" architecture, which means you can add hardware
at any level -- database servers, caching servers or Web/application servers.
The framework cleanly separates components such as its database layer and
application layer. And it ships with a simple-yet-powerful `cache framework`_.
2005-07-15 08:42:28 +08:00
2007-01-25 04:08:47 +08:00
.. _`cache framework`: ../cache/
2005-07-15 08:42:28 +08:00
2005-07-14 03:08:56 +08:00
Who's behind this?
------------------
2005-07-16 00:19:53 +08:00
Django was developed at `World Online`_, the Web department of a newspaper in
Lawrence, Kansas, USA.
2005-07-14 03:08:56 +08:00
`Adrian Holovaty`_
2005-09-20 11:05:37 +08:00
Adrian is a Web developer with a background in journalism. He was lead
developer at World Online for 2.5 years, during which time Django was
2006-05-02 09:31:56 +08:00
developed and implemented on World Online's sites. Now he works for
washingtonpost.com building rich, database-backed information sites, and
continues to oversee Django development. He likes playing guitar (Django
Reinhardt style) and hacking on side projects such as `chicagocrime.org`_.
He lives in Chicago.
2005-07-15 08:42:28 +08:00
2005-08-03 02:00:13 +08:00
On IRC, Adrian goes by ``adrian_h``.
2006-05-02 09:31:56 +08:00
`Jacob Kaplan-Moss`_
Jacob is a whipper-snapper from California who spends equal time coding and
cooking. He's lead developer at 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.
On IRC, Jacob goes by ``jacobkm``.
2005-07-14 03:08:56 +08:00
`Simon Willison`_
2005-07-16 04:37:03 +08:00
Simon is a well-respected Web developer from England. He had a one-year
2005-07-17 10:21:54 +08:00
internship at World Online, during which time he and Adrian developed
2006-05-02 09:31:56 +08:00
Django from scratch. The most enthusiastic Brit you'll ever meet, he's
passionate about best practices in Web development and has maintained a
well-read Web-development blog for years at http://simon.incutio.com.
He works for Yahoo UK, where he managed to score the title "Hacker Liason."
He lives in London.
2005-07-14 03:08:56 +08:00
2005-08-03 02:00:13 +08:00
On IRC, Simon goes by ``SimonW``.
2005-07-15 08:42:28 +08:00
`Wilson Miner`_
2006-09-01 07:16:25 +08:00
Wilson's design-fu makes us all look like rock stars. By day, he's an
2006-08-19 03:10:46 +08:00
interactive designer for `Apple`. Don't ask him what he's working on, or
he'll have to kill you. He lives in San Francisco.
2006-09-01 07:16:25 +08:00
2005-08-03 02:00:13 +08:00
On IRC, Wilson goes by ``wilsonian``.
2005-07-16 00:19:53 +08:00
.. _`World Online`: http://code.djangoproject.com/wiki/WorldOnline
2005-07-14 03:08:56 +08:00
.. _`Adrian Holovaty`: http://www.holovaty.com/
2006-01-21 06:19:04 +08:00
.. _`washingtonpost.com`: http://www.washingtonpost.com/
2005-07-16 00:19:53 +08:00
.. _`chicagocrime.org`: http://www.chicagocrime.org/
2005-07-14 03:08:56 +08:00
.. _`Simon Willison`: http://simon.incutio.com/
2005-07-16 00:19:53 +08:00
.. _`simon.incutio.com`: http://simon.incutio.com/
2005-07-14 03:08:56 +08:00
.. _`Jacob Kaplan-Moss`: http://www.jacobian.org/
2006-06-06 00:28:09 +08:00
.. _`Wilson Miner`: http://www.wilsonminer.com/
2006-08-19 03:10:46 +08:00
.. _`Apple`: http://www.apple.com/
2005-07-14 03:08:56 +08:00
2006-02-23 01:40:30 +08:00
Which sites use Django?
-----------------------
2006-05-02 09:31:56 +08:00
The Django wiki features a consistently growing `list of Django-powered sites`_.
Feel free to add your Django-powered site to the list.
2006-02-23 01:40:30 +08:00
.. _list of Django-powered sites: http://code.djangoproject.com/wiki/DjangoPoweredSites
2005-07-17 01:01:38 +08:00
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?
-----------------------------------------------------------------------------------------------------------------------------------------------------
2006-05-04 05:21:25 +08:00
Well, the standard names are debatable.
2005-07-17 01:01:38 +08:00
2006-05-04 05:21:25 +08:00
In our interpretation of MVC, the "view" describes the data that gets presented
to the user. It's not necessarily *how* the data *looks*, but *which* data is
presented. The view describes *which data you see*, not *how you see it.* It's
a subtle distinction.
2005-07-25 03:02:22 +08:00
2006-05-04 05:21:25 +08:00
So, in our case, a "view" is the Python callback function for a particular URL,
because that callback function describes which data is presented.
Furthermore, it's sensible to separate content from presentation -- which is
where templates come in. In Django, a "view" describes which data is presented,
but a view normally delegates to a template, which describes *how* the data is
presented.
Where does the "controller" fit in, then? In Django's case, it's probably the
framework itself: the machinery that sends a request to the appropriate view,
according to the Django URL configuration.
If you're hungry for acronyms, you might say that Django is a "MTV" framework
-- that is, "model", "template", and "view." That breakdown makes much more
sense.
At the end of the day, of course, it comes down to getting stuff done. And,
regardless of how things are named, Django gets stuff done in a way that's most
logical to us.
2005-07-17 01:01:38 +08:00
2005-07-25 03:02:22 +08:00
<Framework X> does <feature Y> -- why doesn't Django?
-----------------------------------------------------
2005-07-26 00:46:52 +08:00
We're well aware that there are other awesome Web frameworks out there, and
2006-07-24 10:25:41 +08:00
we're not averse to borrowing ideas where appropriate. However, Django was
2005-07-25 03:02:22 +08:00
developed precisely because we were unhappy with the status quo, so please be
aware that "because <Framework X>" does it is not going to be sufficient reason
to add a given feature to Django.
2005-09-20 11:18:05 +08:00
Why did you write all of Django from scratch, instead of using other Python libraries?
--------------------------------------------------------------------------------------
When Django was originally written a couple of years ago, Adrian and Simon
spent quite a bit of time exploring the various Python Web frameworks
available.
In our opinion, none of them were completely up to snuff.
We're picky. You might even call us perfectionists. (With deadlines.)
Over time, we stumbled across open-source libraries that did things we'd
already implemented. It was reassuring to see other people solving similar
problems in similar ways, but it was too late to integrate outside code: We'd
already written, tested and implemented our own framework bits in several
production settings -- and our own code met our needs delightfully.
2005-11-15 15:34:18 +08:00
In most cases, however, we found that existing frameworks/tools inevitably had
some sort of fundamental, fatal flaw that made us squeamish. No tool fit our
2005-11-15 15:36:09 +08:00
philosophies 100%.
2005-11-15 15:34:18 +08:00
Like we said: We're picky.
We've documented our philosophies on the `design philosophies page`_.
2007-01-25 04:08:47 +08:00
.. _design philosophies page: ../design_philosophies/
2005-11-15 15:34:18 +08:00
2005-07-17 01:01:38 +08:00
Do you have any of those nifty "screencast" things?
---------------------------------------------------
2006-01-12 13:41:52 +08:00
You can bet your bottom they're on the way. But, since we're still hammering
out a few points, we want to make sure they reflect the final state of things
at Django 1.0, not some intermediary step. In other words, we don't want to
spend a lot of energy creating screencasts yet, because Django APIs will shift.
In the meantime, though, check out this `unofficial Django screencast`_.
.. _unofficial Django screencast: http://www.throwingbeans.org/django_screencasts.html
2005-07-17 01:01:38 +08:00
2006-06-08 09:52:59 +08:00
Is Django a content-management-system (CMS)?
--------------------------------------------
No, Django is not a CMS, or any sort of "turnkey product" in and of itself.
It's a Web framework; it's a programming tool that lets you build Web sites.
For example, it doesn't make much sense to compare Django to something like
Drupal_, because Django is something you use to *create* things like Drupal.
Of course, Django's automatic admin site is fantastic and timesaving -- but
the admin site is one module of Django the framework. Furthermore, although
Django has special conveniences for building "CMS-y" apps, that doesn't mean
it's not just as appropriate for building "non-CMS-y" apps (whatever that
means!).
.. _Drupal: http://drupal.org/
2006-01-31 06:04:17 +08:00
When will you release Django 1.0?
---------------------------------
Short answer: When we're comfortable with Django's APIs, have added all
features that we feel are necessary to earn a "1.0" status, and are ready to
2006-10-24 07:53:24 +08:00
begin maintaining backwards compatibility.
2006-01-31 06:04:17 +08:00
2006-05-02 09:31:56 +08:00
The merging of Django's `magic-removal branch`_ went a long way toward Django
1.0.
2006-01-31 06:04:17 +08:00
Of course, you should note that `quite a few production sites`_ use Django in
its current status. Don't let the lack of a 1.0 turn you off.
2006-05-02 09:31:56 +08:00
.. _magic-removal branch: http://code.djangoproject.com/wiki/RemovingTheMagic
2006-01-31 06:04:17 +08:00
.. _quite a few production sites: http://code.djangoproject.com/wiki/DjangoPoweredSites
2006-01-24 07:16:39 +08:00
How can I download the Django documentation to read it offline?
---------------------------------------------------------------
The Django docs are available in the ``docs`` directory of each Django tarball
2006-06-08 09:52:59 +08:00
release. These docs are in ReST (ReStructured Text) format, and each text file
2006-01-24 07:16:39 +08:00
corresponds to a Web page on the official Django site.
Because the documentation is `stored in revision control`_, you can browse
documentation changes just like you can browse code changes.
Technically, the docs on Django's site are generated from the latest development
versions of those ReST documents, so the docs on the Django site may offer more
information than the docs that come with the latest Django release.
.. _stored in revision control: http://code.djangoproject.com/browser/django/trunk/docs
2006-07-29 00:25:36 +08:00
Where can I find Django developers for hire?
--------------------------------------------
Consult our `developers for hire page`_ for a list of Django developers who
would be happy to help you.
You might also be interested in posting a job to http://www.gypsyjobs.com/ .
.. _developers for hire page: http://code.djangoproject.com/wiki/DevelopersForHire
2005-07-17 01:01:38 +08:00
Installation questions
======================
2005-07-15 08:42:28 +08:00
How do I get started?
---------------------
2005-07-17 01:01:38 +08:00
#. `Download the code`_.
#. Install Django (read the `installation guide`_).
#. Walk through the tutorial_.
2005-07-19 07:14:48 +08:00
#. Check out the rest of the documentation_, and `ask questions`_ if you
2005-07-17 01:01:38 +08:00
run into trouble.
2005-07-17 05:16:40 +08:00
2005-07-17 01:01:38 +08:00
.. _`Download the code`: http://www.djangoproject.com/download/
2007-01-25 04:08:47 +08:00
.. _`installation guide`: ../install/
.. _tutorial: ../tutorial1/
.. _documentation: ../
2005-07-19 07:14:48 +08:00
.. _ask questions: http://www.djangoproject.com/community/
2005-07-17 01:01:38 +08:00
How do I fix the "install a later version of setuptools" error?
---------------------------------------------------------------
2006-05-02 09:31:56 +08:00
Just run the ``ez_setup.py`` script in the Django distribution.
2005-07-15 08:42:28 +08:00
2005-07-16 04:37:03 +08:00
What are Django's prerequisites?
--------------------------------
2006-06-20 10:52:15 +08:00
Django requires Python_ 2.3 or later. No other Python libraries are required
for basic Django usage.
2005-07-19 07:14:48 +08:00
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.
2005-07-17 05:16:40 +08:00
2006-06-20 10:52:15 +08:00
If you want to use Django with a database, which is probably the case, you'll
also need a database engine. PostgreSQL_ is recommended, because we're
PostgreSQL fans, and MySQL_ and `SQLite 3`_ are also supported.
2005-07-16 04:37:03 +08:00
.. _Python: http://www.python.org/
2005-07-17 05:16:40 +08:00
.. _Apache 2: http://httpd.apache.org/
2005-07-16 04:37:03 +08:00
.. _mod_python: http://www.modpython.org/
2005-07-19 07:14:48 +08:00
.. _WSGI: http://www.python.org/peps/pep-0333.html
2005-07-16 04:37:03 +08:00
.. _PostgreSQL: http://www.postgresql.org/
.. _MySQL: http://www.mysql.com/
2005-07-22 11:15:43 +08:00
.. _`SQLite 3`: http://www.sqlite.org/
2005-07-17 01:01:38 +08:00
2006-09-27 05:57:46 +08:00
Do I lose anything by using Python 2.3 versus newer Python versions, such as Python 2.5?
----------------------------------------------------------------------------------------
No. Django itself is guaranteed to work with any version of Python from 2.3
and higher.
If you use a Python version newer than 2.3, you will, of course, be able to
take advantage of newer Python features in your own code, along with the speed
improvements and other optimizations that have been made to the Python language
itself. But the Django framework itself should work equally well on 2.3 as it
does on 2.4 or 2.5.
2005-07-19 07:14:48 +08:00
Do I have to use mod_python?
----------------------------
2006-06-26 20:43:21 +08:00
Although we recommend mod_python for production use, you don't have to use it,
thanks to the fact that Django uses an arrangement called WSGI_. Django can
2007-04-01 14:40:01 +08:00
talk to any WSGI-enabled server. Other non-mod_python deployment setups are
FastCGI, SCGI or AJP. See `How to use Django with FastCGI, SCGI or AJP`_ for
full information.
2005-07-19 07:14:48 +08:00
2006-06-26 20:43:21 +08:00
Also, see the `server arrangements wiki page`_ for other deployment strategies.
2005-07-19 07:14:48 +08:00
2006-06-26 20:43:21 +08:00
If you just want to play around and develop things on your local computer, use
the development Web server that comes with Django. Things should Just Work.
2005-07-17 01:01:38 +08:00
2005-07-19 07:14:48 +08:00
.. _WSGI: http://www.python.org/peps/pep-0333.html
2007-04-01 14:00:45 +08:00
.. _How to use Django with FastCGI, SCGI or AJP: ../fastcgi/
2006-01-07 01:03:12 +08:00
.. _server arrangements wiki page: http://code.djangoproject.com/wiki/ServerArrangements
2005-07-17 01:01:38 +08:00
2005-07-19 07:14:48 +08:00
How do I install mod_python on Windows?
---------------------------------------
2005-07-17 01:01:38 +08:00
2006-06-19 01:29:59 +08:00
* For Python 2.4, grab mod_python from `win32 build of mod_python for
Python 2.4`_.
* For Python 2.4, check out this `Django on Windows howto`_.
2005-07-22 02:03:25 +08:00
* For Python 2.3, grab mod_python from http://www.modpython.org/ and read
`Running mod_python on Apache on Windows2000`_.
2005-07-26 00:46:52 +08:00
* Also, try this (not Windows-specific) `guide to getting mod_python
2005-07-22 02:03:25 +08:00
working`_.
2005-07-17 05:16:40 +08:00
2006-06-19 01:29:59 +08:00
.. _`win32 build of mod_python for Python 2.4`: http://www.lehuen.com/nicolas/index.php/2005/02/21/39-win32-build-of-mod_python-314-for-python-24
.. _`Django on Windows howto`: http://thinkhole.org/wp/2006/04/03/django-on-windows-howto/
2005-07-17 01:01:38 +08:00
.. _`Running mod_python on Apache on Windows2000`: http://groups-beta.google.com/group/comp.lang.python/msg/139af8c83a5a9d4f
.. _`guide to getting mod_python working`: http://www.dscpl.com.au/articles/modpython-001.html
Will Django run under shared hosting (like TextDrive or Dreamhost)?
-------------------------------------------------------------------
2005-08-03 04:33:02 +08:00
See our `Django-friendly Web hosts`_ page.
.. _`Django-friendly Web hosts`: http://code.djangoproject.com/wiki/DjangoFriendlyWebHosts
2005-07-17 01:13:20 +08:00
2005-11-21 07:49:35 +08:00
Should I use the official version or development version?
---------------------------------------------------------
The Django developers improve Django every day and are pretty good about not
checking in broken code. We use the development code (from the Subversion
repository) directly on our servers, so we consider it stable. With that in
mind, we recommend that you use the latest development code, because it
generally contains more features and fewer bugs than the "official" releases.
2005-07-17 01:13:20 +08:00
Using Django
============
2005-07-17 01:01:38 +08:00
Why do I get an error about importing DJANGO_SETTINGS_MODULE?
-------------------------------------------------------------
Make sure that:
2005-07-17 01:13:20 +08:00
* The environment variable DJANGO_SETTINGS_MODULE is set to a fully-qualified
2007-04-04 05:57:15 +08:00
Python module (i.e. "mysite.settings").
2005-07-17 05:16:40 +08:00
2007-04-04 05:57:15 +08:00
* Said module is on ``sys.path`` (``import mysite.settings`` should work).
2005-07-17 05:16:40 +08:00
2005-07-17 01:01:38 +08:00
* The module doesn't contain syntax errors (of course).
2005-07-17 05:16:40 +08:00
2005-07-17 01:01:38 +08:00
* 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::
2005-07-17 05:16:40 +08:00
2005-07-17 01:01:38 +08:00
os.environ.update(req.subprocess_env)
2005-07-17 05:16:40 +08:00
2005-07-17 01:01:38 +08:00
(where ``req`` is the mod_python request object).
2005-07-17 05:16:40 +08:00
I can't stand your template language. Do I have to use it?
2005-07-17 01:13:20 +08:00
----------------------------------------------------------
We happen to think our template engine is the best thing since chunky bacon,
2005-07-17 05:16:40 +08:00
but we recognize that choosing a template language runs close to religion.
2005-07-17 01:13:20 +08:00
There's nothing about Django that requires using the template language, so
2005-07-17 05:16:40 +08:00
if you're attached to ZPT, Cheetah, or whatever, feel free to use those.
2005-07-17 01:01:38 +08:00
2006-05-02 09:31:56 +08:00
Do I have to use your model/database layer?
-------------------------------------------
Nope. Just like the template system, the model/database layer is decoupled from
2006-06-20 10:52:15 +08:00
the rest of the framework.
The one exception is: If you use a different database library, you won't get to
use Django's automatically-generated admin site. That app is coupled to the
Django database layer.
2006-05-02 09:31:56 +08:00
2005-07-25 03:02:22 +08:00
How do I use image and file fields?
-----------------------------------
Using a ``FileField`` or an ``ImageField`` in a model takes a few steps:
#. In your settings file, define ``MEDIA_ROOT`` as the full path to
2005-07-26 00:46:52 +08:00
a directory where you'd like Django to store uploaded files. (For
performance, these files are not stored in the database.) Define
``MEDIA_URL`` as the base public URL of that directory. Make sure that
this directory is writable by the Web server's user account.
2005-07-25 03:02:22 +08:00
#. Add the ``FileField`` or ``ImageField`` to your model, making sure
2005-07-26 00:46:52 +08:00
to define the ``upload_to`` option to tell Django to which subdirectory
of ``MEDIA_ROOT`` it should upload files.
#. All that will be stored in your database is a path to the file
(relative to ``MEDIA_ROOT``). You'll must likely want to use the
convenience ``get_<fieldname>_url`` function provided by Django. For
example, if your ``ImageField`` is called ``mug_shot``, you can get the
absolute URL to your image in a template with
2005-07-25 03:02:22 +08:00
``{{ object.get_mug_shot_url }}``.
2006-06-29 11:57:19 +08:00
Databases and models
====================
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.db import connection
>>> connection.queries
[{'sql': 'SELECT polls_polls.id,polls_polls.question,polls_polls.pub_date FROM polls_polls',
'time': '0.002'}]
``connection.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.
``connection.queries`` includes all SQL statements -- INSERTs, UPDATES,
SELECTs, etc. Each time your app hits the database, the query will be recorded.
Can I use Django with a pre-existing database?
----------------------------------------------
Yes. See `Integrating with a legacy database`_.
2007-01-25 04:08:47 +08:00
.. _`Integrating with a legacy database`: ../legacy_databases/
2006-06-29 11:57:19 +08:00
2005-09-02 05:48:15 +08:00
If I make changes to a model, how do I update the database?
-----------------------------------------------------------
2006-06-17 10:32:50 +08:00
If you don't mind clearing data, your project's ``manage.py`` utility has an
option to reset the SQL for a particular application::
2005-09-02 05:48:15 +08:00
2006-06-17 10:32:50 +08:00
manage.py reset appname
2005-09-02 05:48:15 +08:00
2006-06-17 10:32:50 +08:00
This drops any tables associated with ``appname`` and recreates them.
2005-09-02 05:51:01 +08:00
2005-09-02 05:48:15 +08:00
If you do care about deleting data, you'll have to execute the ``ALTER TABLE``
statements manually in your database. That's the way we've always done it,
because dealing with data is a very sensitive operation that we've wanted to
2006-05-02 09:31:56 +08:00
avoid automating. That said, there's some work being done to add partially
automated database-upgrade functionality.
2005-09-02 05:48:15 +08:00
2006-02-01 05:38:02 +08:00
Do Django models support multiple-column primary keys?
------------------------------------------------------
No. Only single-column primary keys are supported.
But this isn't an issue in practice, because there's nothing stopping you from
adding other constraints (using the ``unique_together`` model option or
creating the constraint directly in your database), and enforcing the
uniqueness at that level. Single-column primary keys are needed for things such
as the admin interface to work; e.g., you need a simple way of being able to
specify an object to edit or delete.
2006-06-29 11:57:19 +08:00
How do I add database-specific options to my CREATE TABLE statements, such as specifying MyISAM as the table type?
------------------------------------------------------------------------------------------------------------------
2005-07-20 03:55:31 +08:00
2006-09-29 10:30:42 +08:00
We try to avoid adding special cases in the Django code to accommodate all the
2006-06-29 11:57:19 +08:00
database-specific options such as table type, etc. If you'd like to use any of
these options, create an `SQL initial data file`_ that contains ``ALTER TABLE``
statements that do what you want to do. The initial data files are executed in
your database after the ``CREATE TABLE`` statements.
2005-07-20 03:55:31 +08:00
2006-06-29 11:57:19 +08:00
For example, if you're using MySQL and want your tables to use the MyISAM table
type, create an initial data file and put something like this in it::
2005-07-20 03:55:31 +08:00
2006-06-29 11:57:19 +08:00
ALTER TABLE myapp_mytable ENGINE=MyISAM;
2005-07-20 03:55:31 +08:00
2006-06-29 11:57:19 +08:00
As explained in the `SQL initial data file`_ documentation, this SQL file can
contain arbitrary SQL, so you can make any sorts of changes you need to make.
2005-07-20 03:55:31 +08:00
2007-01-25 04:08:47 +08:00
.. _SQL initial data file: ../model_api/#providing-initial-sql-data
2005-08-02 05:40:13 +08:00
2006-06-20 10:52:15 +08:00
Why is Django leaking memory?
-----------------------------
Django isn't known to leak memory. If you find your Django processes are
allocating more and more memory, with no sign of releasing it, check to make
sure your ``DEBUG`` setting is set to ``True``. If ``DEBUG`` is ``True``, then
Django saves a copy of every SQL statement it has executed.
(The queries are saved in ``django.db.connection.queries``. See
2006-06-20 10:57:19 +08:00
`How can I see the raw SQL queries Django is running?`_.)
2006-06-20 10:52:15 +08:00
To fix the problem, set ``DEBUG`` to ``False``.
If you need to clear the query list manually at any point in your functions,
just call ``reset_queries()``, like this::
from django import db
db.reset_queries()
2005-07-17 10:43:18 +08:00
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:
2005-08-17 06:54:05 +08:00
* Set the ``SESSION_COOKIE_DOMAIN`` setting in your admin config file
2005-07-22 02:03:25 +08:00
to match your domain. For example, if you're going to
"http://www.mysite.com/admin/" in your browser, in
2005-10-19 09:09:05 +08:00
"myproject.settings" you should set ``SESSION_COOKIE_DOMAIN = 'www.mysite.com'``.
2005-07-26 00:46:52 +08:00
2005-07-22 02:03:25 +08:00
* 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
2005-08-17 06:54:05 +08:00
``SESSION_COOKIE_DOMAIN`` accordingly.
2005-07-17 10:43:18 +08:00
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.
2005-07-15 08:42:28 +08:00
2006-07-20 23:37:12 +08:00
How can I prevent the cache middleware from caching the admin site?
-------------------------------------------------------------------
Set the ``CACHE_MIDDLEWARE_ANONYMOUS_ONLY`` setting to ``True``. See the
`cache documentation`_ for more information.
.. _cache documentation: ../cache/#the-per-site-cache
2006-01-24 07:22:45 +08:00
How do I automatically set a field's value to the user who last edited the object in the admin?
-----------------------------------------------------------------------------------------------
2006-07-24 10:28:09 +08:00
At this point, Django doesn't have an official way to do this. But it's an oft-requested
feature, so we're discussing how it can be implemented. The problem is we don't want to couple
the model layer with the admin layer with the request layer (to get the current user). It's a
tricky problem.
One person hacked up a `solution that doesn't require patching Django`_, but note that it's an
unofficial solution, and there's no guarantee it won't break at some point.
.. _solution that doesn't require patching Django: http://lukeplant.me.uk/blog.php?id=1107301634
2006-01-24 07:22:45 +08:00
How do I limit admin access so that objects can only be edited by the users who created them?
---------------------------------------------------------------------------------------------
See the answer to the previous question.
2006-01-25 05:42:38 +08:00
My admin-site CSS and images showed up fine using the development server, but they're not displaying when using mod_python.
---------------------------------------------------------------------------------------------------------------------------
See `serving the admin files`_ in the "How to use Django with mod_python"
documentation.
2007-01-25 04:08:47 +08:00
.. _serving the admin files: ../modpython/#serving-the-admin-files
2006-01-25 05:42:38 +08:00
2005-09-20 11:24:01 +08:00
My "list_filter" contains a ManyToManyField, but the filter doesn't display.
----------------------------------------------------------------------------
2006-05-02 09:31:56 +08:00
Django won't bother displaying the filter for a ``ManyToManyField`` if there
are fewer than two related objects.
2005-09-20 11:24:01 +08:00
For example, if your ``list_filter`` includes ``sites``, and there's only one
site in your database, it won't display a "Site" filter. In that case,
filtering by site would be meaningless.
2005-07-20 09:34:08 +08:00
How can I customize the functionality of the admin interface?
-------------------------------------------------------------
You've got several options. If you want to piggyback on top of an add/change
form that Django automatically generates, you can attach arbitrary JavaScript
2006-05-02 09:31:56 +08:00
modules to the page via the model's ``class Admin`` ``js`` parameter. That
parameter is a list of URLs, as strings, pointing to JavaScript modules that
will be included within the admin form via a ``<script>`` tag.
2005-07-20 09:34:08 +08:00
If you want more flexibility than simply tweaking the auto-generated forms,
feel free to write custom views for the admin. The admin is powered by Django
itself, and you can write custom views that hook into the authentication
system, check permissions and do whatever else they need to do.
If you want to customize the look-and-feel of the admin interface, read the
next question.
2005-07-16 00:19:53 +08:00
The dynamically-generated admin site is ugly! How can I change it?
2005-07-16 00:29:26 +08:00
------------------------------------------------------------------
2005-07-15 08:42:28 +08:00
2006-05-02 09:31:56 +08:00
We like it, 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 and plenty of CSS hooks, so any changes you'd
like to make should be possible by editing the stylesheet. We've got a
`guide to the CSS used in the admin`_ to get you started.
2005-07-15 08:42:28 +08:00
2007-01-25 04:08:47 +08:00
.. _`guide to the CSS used in the admin`: ../admin_css/
2006-05-02 09:31:56 +08:00
How do I create users without having to edit password hashes?
-------------------------------------------------------------
2006-08-04 12:20:34 +08:00
If you'd like to use the admin site to create users, upgrade to the Django
development version, where this problem was fixed on Aug. 4, 2006.
2006-05-02 09:31:56 +08:00
2006-08-04 12:20:34 +08:00
You can also use the Python API. See `creating users`_ for full info.
2006-05-02 09:31:56 +08:00
2007-01-25 04:08:47 +08:00
.. _creating users: ../authentication/#creating-users
2006-07-28 00:55:26 +08:00
Contributing code
=================
2006-08-24 07:15:09 +08:00
How can I get started contributing code to Django?
--------------------------------------------------
Thanks for asking! We've written an entire document devoted to this question.
It's titled `Contributing to Django`_.
2007-01-25 04:08:47 +08:00
.. _Contributing to Django: ../contributing/
2006-08-24 07:15:09 +08:00
2006-07-28 00:55:26 +08:00
I submitted a bug fix in the ticket system several weeks ago. Why are you ignoring my patch?
--------------------------------------------------------------------------------------------
Don't worry: We're not ignoring you!
It's important to understand there is a difference between "a ticket is being
ignored" and "a ticket has not been attended to yet." Django's ticket system
contains hundreds of open tickets, of various degrees of impact on end-user
functionality, and Django's developers have to review and prioritize.
Besides, if your feature request stands no chance of inclusion in Django, we
won't ignore it -- we'll just close the ticket. So if your ticket is still
open, it doesn't mean we're ignoring you; it just means we haven't had time to
look at it yet.