thirdparty/google_appengine/lib/django/docs/faq.txt
changeset 109 620f9b141567
equal deleted inserted replaced
108:261778de26ff 109:620f9b141567
       
     1 ==========
       
     2 Django FAQ
       
     3 ==========
       
     4 
       
     5 General questions
       
     6 =================
       
     7 
       
     8 Why does this project exist?
       
     9 ----------------------------
       
    10 
       
    11 Django grew from a very practical need: World Online, a newspaper Web
       
    12 operation, is responsible for building intensive Web applications on journalism
       
    13 deadlines. In the fast-paced newsroom, World Online often has only a matter of
       
    14 hours to take a complicated Web application from concept to public launch.
       
    15 
       
    16 At the same time, the World Online Web developers have consistently been
       
    17 perfectionists when it comes to following best practices of Web development.
       
    18 
       
    19 In fall 2003, the World Online developers (Adrian Holovaty and Simon Willison)
       
    20 ditched PHP and began using Python to develop its Web sites. As they built
       
    21 intensive, richly interactive sites such as Lawrence.com, they began to extract
       
    22 a generic Web development framework that let them build Web applications more
       
    23 and more quickly. They tweaked this framework constantly, adding improvements
       
    24 over two years.
       
    25 
       
    26 In summer 2005, World Online decided to open-source the resulting software,
       
    27 Django. Django would not be possible without a whole host of open-source
       
    28 projects -- `Apache`_, `Python`_, and `PostgreSQL`_ to name a few -- and we're
       
    29 thrilled to be able to give something back to the open-source community.
       
    30 
       
    31 .. _Apache: http://httpd.apache.org/
       
    32 .. _Python: http://www.python.org/
       
    33 .. _PostgreSQL: http://www.postgresql.org/
       
    34 
       
    35 What does "Django" mean, and how do you pronounce it?
       
    36 -----------------------------------------------------
       
    37 
       
    38 Django is named after `Django Reinhardt`_, a gypsy jazz guitarist from the 1930s
       
    39 to early 1950s. To this day, he's considered one of the best guitarists of all time.
       
    40 
       
    41 Listen to his music. You'll like it.
       
    42 
       
    43 Django is pronounced **JANG**-oh. Rhymes with FANG-oh. The "D" is silent.
       
    44 
       
    45 .. _Django Reinhardt: http://en.wikipedia.org/wiki/Django_Reinhardt
       
    46 
       
    47 Is Django stable?
       
    48 -----------------
       
    49 
       
    50 Yes. World Online has been using Django for more than three years. Sites built
       
    51 on Django have weathered traffic spikes of over one million hits an hour and a
       
    52 number of Slashdottings. Yes, it's quite stable.
       
    53 
       
    54 Does Django scale?
       
    55 ------------------
       
    56 
       
    57 Yes. Compared to development time, hardware is cheap, and so Django is
       
    58 designed to take advantage of as much hardware as you can throw at it.
       
    59 
       
    60 Django uses a "shared-nothing" architecture, which means you can add hardware
       
    61 at any level -- database servers, caching servers or Web/application servers.
       
    62 
       
    63 The framework cleanly separates components such as its database layer and
       
    64 application layer. And it ships with a simple-yet-powerful `cache framework`_.
       
    65 
       
    66 .. _`cache framework`: ../cache/
       
    67 
       
    68 Who's behind this?
       
    69 ------------------
       
    70 
       
    71 Django was developed at `World Online`_, the Web department of a newspaper in
       
    72 Lawrence, Kansas, USA.
       
    73 
       
    74 `Adrian Holovaty`_
       
    75     Adrian is a Web developer with a background in journalism. He was lead
       
    76     developer at World Online for 2.5 years, during which time Django was
       
    77     developed and implemented on World Online's sites. Now he works for
       
    78     washingtonpost.com building rich, database-backed information sites, and
       
    79     continues to oversee Django development. He likes playing guitar (Django
       
    80     Reinhardt style) and hacking on side projects such as `chicagocrime.org`_.
       
    81     He lives in Chicago.
       
    82 
       
    83     On IRC, Adrian goes by ``adrian_h``.
       
    84 
       
    85 `Jacob Kaplan-Moss`_
       
    86     Jacob is a whipper-snapper from California who spends equal time coding and
       
    87     cooking. He's lead developer at World Online and actively hacks on various
       
    88     cool side projects. He's contributed to the Python-ObjC bindings and was
       
    89     the first guy to figure out how to write Tivo apps in Python. Lately he's
       
    90     been messing with Python on the PSP. He lives in Lawrence, Kansas.
       
    91 
       
    92     On IRC, Jacob goes by ``jacobkm``.
       
    93 
       
    94 `Simon Willison`_
       
    95     Simon is a well-respected Web developer from England. He had a one-year
       
    96     internship at World Online, during which time he and Adrian developed
       
    97     Django from scratch. The most enthusiastic Brit you'll ever meet, he's
       
    98     passionate about best practices in Web development and has maintained a
       
    99     well-read Web-development blog for years at http://simon.incutio.com.
       
   100     He works for Yahoo UK, where he managed to score the title "Hacker Liason."
       
   101     He lives in London.
       
   102 
       
   103     On IRC, Simon goes by ``SimonW``.
       
   104 
       
   105 `Wilson Miner`_
       
   106     Wilson's design-fu makes us all look like rock stars. By day, he's an
       
   107     interactive designer for `Apple`. Don't ask him what he's working on, or
       
   108     he'll have to kill you. He lives in San Francisco.
       
   109 
       
   110     On IRC, Wilson goes by ``wilsonian``.
       
   111 
       
   112 .. _`World Online`: http://code.djangoproject.com/wiki/WorldOnline
       
   113 .. _`Adrian Holovaty`: http://www.holovaty.com/
       
   114 .. _`washingtonpost.com`: http://www.washingtonpost.com/
       
   115 .. _`chicagocrime.org`: http://www.chicagocrime.org/
       
   116 .. _`Simon Willison`: http://simon.incutio.com/
       
   117 .. _`simon.incutio.com`: http://simon.incutio.com/
       
   118 .. _`Jacob Kaplan-Moss`: http://www.jacobian.org/
       
   119 .. _`Wilson Miner`: http://www.wilsonminer.com/
       
   120 .. _`Apple`: http://www.apple.com/
       
   121 
       
   122 Which sites use Django?
       
   123 -----------------------
       
   124 
       
   125 The Django wiki features a consistently growing `list of Django-powered sites`_.
       
   126 Feel free to add your Django-powered site to the list.
       
   127 
       
   128 .. _list of Django-powered sites: http://code.djangoproject.com/wiki/DjangoPoweredSites
       
   129 
       
   130 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?
       
   131 -----------------------------------------------------------------------------------------------------------------------------------------------------
       
   132 
       
   133 Well, the standard names are debatable.
       
   134 
       
   135 In our interpretation of MVC, the "view" describes the data that gets presented
       
   136 to the user. It's not necessarily *how* the data *looks*, but *which* data is
       
   137 presented. The view describes *which data you see*, not *how you see it.* It's
       
   138 a subtle distinction.
       
   139 
       
   140 So, in our case, a "view" is the Python callback function for a particular URL,
       
   141 because that callback function describes which data is presented.
       
   142 
       
   143 Furthermore, it's sensible to separate content from presentation -- which is
       
   144 where templates come in. In Django, a "view" describes which data is presented,
       
   145 but a view normally delegates to a template, which describes *how* the data is
       
   146 presented.
       
   147 
       
   148 Where does the "controller" fit in, then? In Django's case, it's probably the
       
   149 framework itself: the machinery that sends a request to the appropriate view,
       
   150 according to the Django URL configuration.
       
   151 
       
   152 If you're hungry for acronyms, you might say that Django is a "MTV" framework
       
   153 -- that is, "model", "template", and "view." That breakdown makes much more
       
   154 sense.
       
   155 
       
   156 At the end of the day, of course, it comes down to getting stuff done. And,
       
   157 regardless of how things are named, Django gets stuff done in a way that's most
       
   158 logical to us.
       
   159 
       
   160 <Framework X> does <feature Y> -- why doesn't Django?
       
   161 -----------------------------------------------------
       
   162 
       
   163 We're well aware that there are other awesome Web frameworks out there, and
       
   164 we're not averse to borrowing ideas where appropriate. However, Django was
       
   165 developed precisely because we were unhappy with the status quo, so please be
       
   166 aware that "because <Framework X>" does it is not going to be sufficient reason
       
   167 to add a given feature to Django.
       
   168 
       
   169 Why did you write all of Django from scratch, instead of using other Python libraries?
       
   170 --------------------------------------------------------------------------------------
       
   171 
       
   172 When Django was originally written a couple of years ago, Adrian and Simon
       
   173 spent quite a bit of time exploring the various Python Web frameworks
       
   174 available.
       
   175 
       
   176 In our opinion, none of them were completely up to snuff.
       
   177 
       
   178 We're picky. You might even call us perfectionists. (With deadlines.)
       
   179 
       
   180 Over time, we stumbled across open-source libraries that did things we'd
       
   181 already implemented. It was reassuring to see other people solving similar
       
   182 problems in similar ways, but it was too late to integrate outside code: We'd
       
   183 already written, tested and implemented our own framework bits in several
       
   184 production settings -- and our own code met our needs delightfully.
       
   185 
       
   186 In most cases, however, we found that existing frameworks/tools inevitably had
       
   187 some sort of fundamental, fatal flaw that made us squeamish. No tool fit our
       
   188 philosophies 100%.
       
   189 
       
   190 Like we said: We're picky.
       
   191 
       
   192 We've documented our philosophies on the `design philosophies page`_.
       
   193 
       
   194 .. _design philosophies page: ../design_philosophies/
       
   195 
       
   196 Do you have any of those nifty "screencast" things?
       
   197 ---------------------------------------------------
       
   198 
       
   199 You can bet your bottom they're on the way. But, since we're still hammering
       
   200 out a few points, we want to make sure they reflect the final state of things
       
   201 at Django 1.0, not some intermediary step. In other words, we don't want to
       
   202 spend a lot of energy creating screencasts yet, because Django APIs will shift.
       
   203 
       
   204 In the meantime, though, check out this `unofficial Django screencast`_.
       
   205 
       
   206 .. _unofficial Django screencast: http://www.throwingbeans.org/django_screencasts.html
       
   207 
       
   208 Is Django a content-management-system (CMS)?
       
   209 --------------------------------------------
       
   210 
       
   211 No, Django is not a CMS, or any sort of "turnkey product" in and of itself.
       
   212 It's a Web framework; it's a programming tool that lets you build Web sites.
       
   213 
       
   214 For example, it doesn't make much sense to compare Django to something like
       
   215 Drupal_, because Django is something you use to *create* things like Drupal.
       
   216 
       
   217 Of course, Django's automatic admin site is fantastic and timesaving -- but
       
   218 the admin site is one module of Django the framework. Furthermore, although
       
   219 Django has special conveniences for building "CMS-y" apps, that doesn't mean
       
   220 it's not just as appropriate for building "non-CMS-y" apps (whatever that
       
   221 means!).
       
   222 
       
   223 .. _Drupal: http://drupal.org/
       
   224 
       
   225 When will you release Django 1.0?
       
   226 ---------------------------------
       
   227 
       
   228 Short answer: When we're comfortable with Django's APIs, have added all
       
   229 features that we feel are necessary to earn a "1.0" status, and are ready to
       
   230 begin maintaining backwards compatibility. 
       
   231 
       
   232 The merging of Django's `magic-removal branch`_ went a long way toward Django
       
   233 1.0.
       
   234 
       
   235 Of course, you should note that `quite a few production sites`_ use Django in
       
   236 its current status. Don't let the lack of a 1.0 turn you off.
       
   237 
       
   238 .. _magic-removal branch: http://code.djangoproject.com/wiki/RemovingTheMagic
       
   239 .. _quite a few production sites: http://code.djangoproject.com/wiki/DjangoPoweredSites
       
   240 
       
   241 How can I download the Django documentation to read it offline?
       
   242 ---------------------------------------------------------------
       
   243 
       
   244 The Django docs are available in the ``docs`` directory of each Django tarball
       
   245 release. These docs are in ReST (ReStructured Text) format, and each text file
       
   246 corresponds to a Web page on the official Django site.
       
   247 
       
   248 Because the documentation is `stored in revision control`_, you can browse
       
   249 documentation changes just like you can browse code changes.
       
   250 
       
   251 Technically, the docs on Django's site are generated from the latest development
       
   252 versions of those ReST documents, so the docs on the Django site may offer more
       
   253 information than the docs that come with the latest Django release.
       
   254 
       
   255 .. _stored in revision control: http://code.djangoproject.com/browser/django/trunk/docs
       
   256 
       
   257 Where can I find Django developers for hire?
       
   258 --------------------------------------------
       
   259 
       
   260 Consult our `developers for hire page`_ for a list of Django developers who
       
   261 would be happy to help you.
       
   262 
       
   263 You might also be interested in posting a job to http://www.gypsyjobs.com/ .
       
   264 
       
   265 .. _developers for hire page: http://code.djangoproject.com/wiki/DevelopersForHire
       
   266 
       
   267 Installation questions
       
   268 ======================
       
   269 
       
   270 How do I get started?
       
   271 ---------------------
       
   272 
       
   273     #. `Download the code`_.
       
   274     #. Install Django (read the `installation guide`_).
       
   275     #. Walk through the tutorial_.
       
   276     #. Check out the rest of the documentation_, and `ask questions`_ if you
       
   277        run into trouble.
       
   278 
       
   279 .. _`Download the code`: http://www.djangoproject.com/download/
       
   280 .. _`installation guide`: ../install/
       
   281 .. _tutorial:  ../tutorial1/
       
   282 .. _documentation: ../
       
   283 .. _ask questions: http://www.djangoproject.com/community/
       
   284 
       
   285 How do I fix the "install a later version of setuptools" error?
       
   286 ---------------------------------------------------------------
       
   287 
       
   288 Just run the ``ez_setup.py`` script in the Django distribution.
       
   289 
       
   290 What are Django's prerequisites?
       
   291 --------------------------------
       
   292 
       
   293 Django requires Python_ 2.3 or later. No other Python libraries are required
       
   294 for basic Django usage.
       
   295 
       
   296 For a development environment -- if you just want to experiment with Django --
       
   297 you don't need to have a separate Web server installed; Django comes with its
       
   298 own lightweight development server. For a production environment, we recommend
       
   299 `Apache 2`_ and mod_python_, although Django follows the WSGI_ spec, which
       
   300 means it can run on a variety of server platforms.
       
   301 
       
   302 If you want to use Django with a database, which is probably the case, you'll
       
   303 also need a database engine. PostgreSQL_ is recommended, because we're
       
   304 PostgreSQL fans, and MySQL_ and `SQLite 3`_ are also supported.
       
   305 
       
   306 .. _Python: http://www.python.org/
       
   307 .. _Apache 2: http://httpd.apache.org/
       
   308 .. _mod_python: http://www.modpython.org/
       
   309 .. _WSGI: http://www.python.org/peps/pep-0333.html
       
   310 .. _PostgreSQL: http://www.postgresql.org/
       
   311 .. _MySQL: http://www.mysql.com/
       
   312 .. _`SQLite 3`: http://www.sqlite.org/
       
   313 
       
   314 Do I lose anything by using Python 2.3 versus newer Python versions, such as Python 2.5?
       
   315 ----------------------------------------------------------------------------------------
       
   316 
       
   317 No. Django itself is guaranteed to work with any version of Python from 2.3
       
   318 and higher.
       
   319 
       
   320 If you use a Python version newer than 2.3, you will, of course, be able to
       
   321 take advantage of newer Python features in your own code, along with the speed
       
   322 improvements and other optimizations that have been made to the Python language
       
   323 itself. But the Django framework itself should work equally well on 2.3 as it
       
   324 does on 2.4 or 2.5.
       
   325 
       
   326 Do I have to use mod_python?
       
   327 ----------------------------
       
   328 
       
   329 Although we recommend mod_python for production use, you don't have to use it,
       
   330 thanks to the fact that Django uses an arrangement called WSGI_. Django can
       
   331 talk to any WSGI-enabled server. The most common non-mod_python deployment
       
   332 setup is FastCGI. See `How to use Django with FastCGI`_ for full information.
       
   333 
       
   334 Also, see the `server arrangements wiki page`_ for other deployment strategies.
       
   335 
       
   336 If you just want to play around and develop things on your local computer, use
       
   337 the development Web server that comes with Django. Things should Just Work.
       
   338 
       
   339 .. _WSGI: http://www.python.org/peps/pep-0333.html
       
   340 .. _How to use Django with FastCGI: ../fastcgi/
       
   341 .. _server arrangements wiki page: http://code.djangoproject.com/wiki/ServerArrangements
       
   342 
       
   343 How do I install mod_python on Windows?
       
   344 ---------------------------------------
       
   345 
       
   346     * For Python 2.4, grab mod_python from `win32 build of mod_python for
       
   347       Python 2.4`_.
       
   348     * For Python 2.4, check out this `Django on Windows howto`_.
       
   349     * For Python 2.3, grab mod_python from http://www.modpython.org/ and read
       
   350       `Running mod_python on Apache on Windows2000`_.
       
   351     * Also, try this (not Windows-specific) `guide to getting mod_python
       
   352       working`_.
       
   353 
       
   354 .. _`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
       
   355 .. _`Django on Windows howto`: http://thinkhole.org/wp/2006/04/03/django-on-windows-howto/
       
   356 .. _`Running mod_python on Apache on Windows2000`: http://groups-beta.google.com/group/comp.lang.python/msg/139af8c83a5a9d4f
       
   357 .. _`guide to getting mod_python working`: http://www.dscpl.com.au/articles/modpython-001.html
       
   358 
       
   359 Will Django run under shared hosting (like TextDrive or Dreamhost)?
       
   360 -------------------------------------------------------------------
       
   361 
       
   362 See our `Django-friendly Web hosts`_ page.
       
   363 
       
   364 .. _`Django-friendly Web hosts`: http://code.djangoproject.com/wiki/DjangoFriendlyWebHosts
       
   365 
       
   366 Should I use the official version or development version?
       
   367 ---------------------------------------------------------
       
   368 
       
   369 The Django developers improve Django every day and are pretty good about not
       
   370 checking in broken code. We use the development code (from the Subversion
       
   371 repository) directly on our servers, so we consider it stable. With that in
       
   372 mind, we recommend that you use the latest development code, because it
       
   373 generally contains more features and fewer bugs than the "official" releases.
       
   374 
       
   375 Using Django
       
   376 ============
       
   377 
       
   378 Why do I get an error about importing DJANGO_SETTINGS_MODULE?
       
   379 -------------------------------------------------------------
       
   380 
       
   381 Make sure that:
       
   382 
       
   383     * The environment variable DJANGO_SETTINGS_MODULE is set to a fully-qualified
       
   384       Python module (i.e. "mysite.settings.main").
       
   385 
       
   386     * Said module is on ``sys.path`` (``import mysite.settings.main`` should work).
       
   387 
       
   388     * The module doesn't contain syntax errors (of course).
       
   389 
       
   390     * If you're using mod_python but *not* using Django's request handler,
       
   391       you'll need to work around a mod_python bug related to the use of
       
   392       ``SetEnv``; before you import anything from Django you'll need to do
       
   393       the following::
       
   394 
       
   395             os.environ.update(req.subprocess_env)
       
   396 
       
   397       (where ``req`` is the mod_python request object).
       
   398 
       
   399 I can't stand your template language. Do I have to use it?
       
   400 ----------------------------------------------------------
       
   401 
       
   402 We happen to think our template engine is the best thing since chunky bacon,
       
   403 but we recognize that choosing a template language runs close to religion.
       
   404 There's nothing about Django that requires using the template language, so
       
   405 if you're attached to ZPT, Cheetah, or whatever, feel free to use those.
       
   406 
       
   407 Do I have to use your model/database layer?
       
   408 -------------------------------------------
       
   409 
       
   410 Nope. Just like the template system, the model/database layer is decoupled from
       
   411 the rest of the framework.
       
   412 
       
   413 The one exception is: If you use a different database library, you won't get to
       
   414 use Django's automatically-generated admin site. That app is coupled to the
       
   415 Django database layer.
       
   416 
       
   417 How do I use image and file fields?
       
   418 -----------------------------------
       
   419 
       
   420 Using a ``FileField`` or an ``ImageField`` in a model takes a few steps:
       
   421 
       
   422     #. In your settings file, define ``MEDIA_ROOT`` as the full path to
       
   423        a directory where you'd like Django to store uploaded files. (For
       
   424        performance, these files are not stored in the database.) Define
       
   425        ``MEDIA_URL`` as the base public URL of that directory. Make sure that
       
   426        this directory is writable by the Web server's user account.
       
   427 
       
   428     #. Add the ``FileField`` or ``ImageField`` to your model, making sure
       
   429        to define the ``upload_to`` option to tell Django to which subdirectory
       
   430        of ``MEDIA_ROOT`` it should upload files.
       
   431 
       
   432     #. All that will be stored in your database is a path to the file
       
   433        (relative to ``MEDIA_ROOT``). You'll must likely want to use the
       
   434        convenience ``get_<fieldname>_url`` function provided by Django. For
       
   435        example, if your ``ImageField`` is called ``mug_shot``, you can get the
       
   436        absolute URL to your image in a template with
       
   437        ``{{ object.get_mug_shot_url }}``.
       
   438 
       
   439 Databases and models
       
   440 ====================
       
   441 
       
   442 How can I see the raw SQL queries Django is running?
       
   443 ----------------------------------------------------
       
   444 
       
   445 Make sure your Django ``DEBUG`` setting is set to ``True``. Then, just do
       
   446 this::
       
   447 
       
   448     >>> from django.db import connection
       
   449     >>> connection.queries
       
   450     [{'sql': 'SELECT polls_polls.id,polls_polls.question,polls_polls.pub_date FROM polls_polls',
       
   451     'time': '0.002'}]
       
   452 
       
   453 ``connection.queries`` is only available if ``DEBUG`` is ``True``. It's a list
       
   454 of dictionaries in order of query execution. Each dictionary has the following::
       
   455 
       
   456     ``sql`` -- The raw SQL statement
       
   457     ``time`` -- How long the statement took to execute, in seconds.
       
   458 
       
   459 ``connection.queries`` includes all SQL statements -- INSERTs, UPDATES,
       
   460 SELECTs, etc. Each time your app hits the database, the query will be recorded.
       
   461 
       
   462 Can I use Django with a pre-existing database?
       
   463 ----------------------------------------------
       
   464 
       
   465 Yes. See `Integrating with a legacy database`_.
       
   466 
       
   467 .. _`Integrating with a legacy database`: ../legacy_databases/
       
   468 
       
   469 If I make changes to a model, how do I update the database?
       
   470 -----------------------------------------------------------
       
   471 
       
   472 If you don't mind clearing data, your project's ``manage.py`` utility has an
       
   473 option to reset the SQL for a particular application::
       
   474 
       
   475     manage.py reset appname
       
   476 
       
   477 This drops any tables associated with ``appname`` and recreates them.
       
   478 
       
   479 If you do care about deleting data, you'll have to execute the ``ALTER TABLE``
       
   480 statements manually in your database. That's the way we've always done it,
       
   481 because dealing with data is a very sensitive operation that we've wanted to
       
   482 avoid automating. That said, there's some work being done to add partially
       
   483 automated database-upgrade functionality.
       
   484 
       
   485 Do Django models support multiple-column primary keys?
       
   486 ------------------------------------------------------
       
   487 
       
   488 No. Only single-column primary keys are supported.
       
   489 
       
   490 But this isn't an issue in practice, because there's nothing stopping you from
       
   491 adding other constraints (using the ``unique_together`` model option or
       
   492 creating the constraint directly in your database), and enforcing the
       
   493 uniqueness at that level. Single-column primary keys are needed for things such
       
   494 as the admin interface to work; e.g., you need a simple way of being able to
       
   495 specify an object to edit or delete.
       
   496 
       
   497 How do I add database-specific options to my CREATE TABLE statements, such as specifying MyISAM as the table type?
       
   498 ------------------------------------------------------------------------------------------------------------------
       
   499 
       
   500 We try to avoid adding special cases in the Django code to accommodate all the
       
   501 database-specific options such as table type, etc. If you'd like to use any of
       
   502 these options, create an `SQL initial data file`_ that contains ``ALTER TABLE``
       
   503 statements that do what you want to do. The initial data files are executed in
       
   504 your database after the ``CREATE TABLE`` statements.
       
   505 
       
   506 For example, if you're using MySQL and want your tables to use the MyISAM table
       
   507 type, create an initial data file and put something like this in it::
       
   508 
       
   509     ALTER TABLE myapp_mytable ENGINE=MyISAM;
       
   510 
       
   511 As explained in the `SQL initial data file`_ documentation, this SQL file can
       
   512 contain arbitrary SQL, so you can make any sorts of changes you need to make.
       
   513 
       
   514 .. _SQL initial data file: ../model_api/#providing-initial-sql-data
       
   515 
       
   516 Why is Django leaking memory?
       
   517 -----------------------------
       
   518 
       
   519 Django isn't known to leak memory. If you find your Django processes are
       
   520 allocating more and more memory, with no sign of releasing it, check to make
       
   521 sure your ``DEBUG`` setting is set to ``True``. If ``DEBUG`` is ``True``, then
       
   522 Django saves a copy of every SQL statement it has executed.
       
   523 
       
   524 (The queries are saved in ``django.db.connection.queries``. See
       
   525 `How can I see the raw SQL queries Django is running?`_.)
       
   526 
       
   527 To fix the problem, set ``DEBUG`` to ``False``.
       
   528 
       
   529 If you need to clear the query list manually at any point in your functions,
       
   530 just call ``reset_queries()``, like this::
       
   531 
       
   532     from django import db
       
   533     db.reset_queries()
       
   534 
       
   535 The admin site
       
   536 ==============
       
   537 
       
   538 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.
       
   539 ---------------------------------------------------------------------------------------------------------------------------
       
   540 
       
   541 The login cookie isn't being set correctly, because the domain of the cookie
       
   542 sent out by Django doesn't match the domain in your browser. Try these two
       
   543 things:
       
   544 
       
   545     * Set the ``SESSION_COOKIE_DOMAIN`` setting in your admin config file
       
   546       to match your domain. For example, if you're going to
       
   547       "http://www.mysite.com/admin/" in your browser, in
       
   548       "myproject.settings" you should set ``SESSION_COOKIE_DOMAIN = 'www.mysite.com'``.
       
   549 
       
   550     * Some browsers (Firefox?) don't like to accept cookies from domains that
       
   551       don't have dots in them. If you're running the admin site on "localhost"
       
   552       or another domain that doesn't have a dot in it, try going to
       
   553       "localhost.localdomain" or "127.0.0.1". And set
       
   554       ``SESSION_COOKIE_DOMAIN`` accordingly.
       
   555 
       
   556 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.
       
   557 -----------------------------------------------------------------------------------------------------------------------------------------------------------
       
   558 
       
   559 If you're sure your username and password are correct, make sure your user
       
   560 account has ``is_active`` and ``is_staff`` set to True. The admin site only
       
   561 allows access to users with those two fields both set to True.
       
   562 
       
   563 How can I prevent the cache middleware from caching the admin site?
       
   564 -------------------------------------------------------------------
       
   565 
       
   566 Set the ``CACHE_MIDDLEWARE_ANONYMOUS_ONLY`` setting to ``True``. See the
       
   567 `cache documentation`_ for more information.
       
   568 
       
   569 .. _cache documentation: ../cache/#the-per-site-cache
       
   570 
       
   571 How do I automatically set a field's value to the user who last edited the object in the admin?
       
   572 -----------------------------------------------------------------------------------------------
       
   573 
       
   574 At this point, Django doesn't have an official way to do this. But it's an oft-requested
       
   575 feature, so we're discussing how it can be implemented. The problem is we don't want to couple
       
   576 the model layer with the admin layer with the request layer (to get the current user). It's a
       
   577 tricky problem.
       
   578 
       
   579 One person hacked up a `solution that doesn't require patching Django`_, but note that it's an
       
   580 unofficial solution, and there's no guarantee it won't break at some point.
       
   581 
       
   582 .. _solution that doesn't require patching Django: http://lukeplant.me.uk/blog.php?id=1107301634
       
   583 
       
   584 How do I limit admin access so that objects can only be edited by the users who created them?
       
   585 ---------------------------------------------------------------------------------------------
       
   586 
       
   587 See the answer to the previous question.
       
   588 
       
   589 My admin-site CSS and images showed up fine using the development server, but they're not displaying when using mod_python.
       
   590 ---------------------------------------------------------------------------------------------------------------------------
       
   591 
       
   592 See `serving the admin files`_ in the "How to use Django with mod_python"
       
   593 documentation.
       
   594 
       
   595 .. _serving the admin files: ../modpython/#serving-the-admin-files
       
   596 
       
   597 My "list_filter" contains a ManyToManyField, but the filter doesn't display.
       
   598 ----------------------------------------------------------------------------
       
   599 
       
   600 Django won't bother displaying the filter for a ``ManyToManyField`` if there
       
   601 are fewer than two related objects.
       
   602 
       
   603 For example, if your ``list_filter`` includes ``sites``, and there's only one
       
   604 site in your database, it won't display a "Site" filter. In that case,
       
   605 filtering by site would be meaningless.
       
   606 
       
   607 How can I customize the functionality of the admin interface?
       
   608 -------------------------------------------------------------
       
   609 
       
   610 You've got several options. If you want to piggyback on top of an add/change
       
   611 form that Django automatically generates, you can attach arbitrary JavaScript
       
   612 modules to the page via the model's ``class Admin`` ``js`` parameter. That
       
   613 parameter is a list of URLs, as strings, pointing to JavaScript modules that
       
   614 will be included within the admin form via a ``<script>`` tag.
       
   615 
       
   616 If you want more flexibility than simply tweaking the auto-generated forms,
       
   617 feel free to write custom views for the admin. The admin is powered by Django
       
   618 itself, and you can write custom views that hook into the authentication
       
   619 system, check permissions and do whatever else they need to do.
       
   620 
       
   621 If you want to customize the look-and-feel of the admin interface, read the
       
   622 next question.
       
   623 
       
   624 The dynamically-generated admin site is ugly! How can I change it?
       
   625 ------------------------------------------------------------------
       
   626 
       
   627 We like it, but if you don't agree, you can modify the admin site's
       
   628 presentation by editing the CSS stylesheet and/or associated image files. The
       
   629 site is built using semantic HTML and plenty of CSS hooks, so any changes you'd
       
   630 like to make should be possible by editing the stylesheet. We've got a
       
   631 `guide to the CSS used in the admin`_ to get you started.
       
   632 
       
   633 .. _`guide to the CSS used in the admin`: ../admin_css/
       
   634 
       
   635 How do I create users without having to edit password hashes?
       
   636 -------------------------------------------------------------
       
   637 
       
   638 If you'd like to use the admin site to create users, upgrade to the Django
       
   639 development version, where this problem was fixed on Aug. 4, 2006.
       
   640 
       
   641 You can also use the Python API. See `creating users`_ for full info.
       
   642 
       
   643 .. _creating users: ../authentication/#creating-users
       
   644 
       
   645 Contributing code
       
   646 =================
       
   647 
       
   648 How can I get started contributing code to Django?
       
   649 --------------------------------------------------
       
   650 
       
   651 Thanks for asking! We've written an entire document devoted to this question.
       
   652 It's titled `Contributing to Django`_.
       
   653 
       
   654 .. _Contributing to Django: ../contributing/
       
   655 
       
   656 I submitted a bug fix in the ticket system several weeks ago. Why are you ignoring my patch?
       
   657 --------------------------------------------------------------------------------------------
       
   658 
       
   659 Don't worry: We're not ignoring you!
       
   660 
       
   661 It's important to understand there is a difference between "a ticket is being
       
   662 ignored" and "a ticket has not been attended to yet." Django's ticket system
       
   663 contains hundreds of open tickets, of various degrees of impact on end-user
       
   664 functionality, and Django's developers have to review and prioritize.
       
   665 
       
   666 Besides, if your feature request stands no chance of inclusion in Django, we
       
   667 won't ignore it -- we'll just close the ticket. So if your ticket is still
       
   668 open, it doesn't mean we're ignoring you; it just means we haven't had time to
       
   669 look at it yet.