admin.txt 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. FAQ: The admin
  2. ==============
  3. 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.
  4. ---------------------------------------------------------------------------------------------------------------------------
  5. The login cookie isn't being set correctly, because the domain of the cookie
  6. sent out by Django doesn't match the domain in your browser. Try these two
  7. things:
  8. * Set the :setting:`SESSION_COOKIE_DOMAIN` setting in your admin config
  9. file to match your domain. For example, if you're going to
  10. "http://www.example.com/admin/" in your browser, in
  11. "myproject.settings" you should set ``SESSION_COOKIE_DOMAIN = 'www.example.com'``.
  12. * Some browsers (Firefox?) don't like to accept cookies from domains that
  13. don't have dots in them. If you're running the admin site on "localhost"
  14. or another domain that doesn't have a dot in it, try going to
  15. "localhost.localdomain" or "127.0.0.1". And set
  16. :setting:`SESSION_COOKIE_DOMAIN` accordingly.
  17. 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.
  18. -----------------------------------------------------------------------------------------------------------------------------------------------------------
  19. If you're sure your username and password are correct, make sure your user
  20. account has ``is_active`` and ``is_staff`` set to True. The admin site only
  21. allows access to users with those two fields both set to True.
  22. How can I prevent the cache middleware from caching the admin site?
  23. -------------------------------------------------------------------
  24. Set the :setting:`CACHE_MIDDLEWARE_ANONYMOUS_ONLY` setting to ``True``. See the
  25. :doc:`cache documentation </topics/cache>` for more information.
  26. How do I automatically set a field's value to the user who last edited the object in the admin?
  27. -----------------------------------------------------------------------------------------------
  28. The :class:`~django.contrib.admin.ModelAdmin` class provides customization hooks
  29. that allow you to transform an object as it saved, using details from the
  30. request. By extracting the current user from the request, and customizing the
  31. :meth:`~django.contrib.admin.ModelAdmin.save_model` hook, you can update an
  32. object to reflect the user that edited it. See :ref:`the documentation on
  33. ModelAdmin methods <model-admin-methods>` for an example.
  34. How do I limit admin access so that objects can only be edited by the users who created them?
  35. ---------------------------------------------------------------------------------------------
  36. The :class:`~django.contrib.admin.ModelAdmin` class also provides customization
  37. hooks that allow you to control the visibility and editability of objects in the
  38. admin. Using the same trick of extracting the user from the request, the
  39. :meth:`~django.contrib.admin.ModelAdmin.queryset` and
  40. :meth:`~django.contrib.admin.ModelAdmin.has_change_permission` can be used to
  41. control the visibility and editability of objects in the admin.
  42. My admin-site CSS and images showed up fine using the development server, but they're not displaying when using mod_wsgi.
  43. ---------------------------------------------------------------------------------------------------------------------------
  44. See :ref:`serving the admin files <serving-the-admin-files>`
  45. in the "How to use Django with mod_wsgi" documentation.
  46. My "list_filter" contains a ManyToManyField, but the filter doesn't display.
  47. ----------------------------------------------------------------------------
  48. Django won't bother displaying the filter for a ``ManyToManyField`` if there
  49. are fewer than two related objects.
  50. For example, if your ``list_filter`` includes ``sites``, and there's only one
  51. site in your database, it won't display a "Site" filter. In that case,
  52. filtering by site would be meaningless.
  53. How can I customize the functionality of the admin interface?
  54. -------------------------------------------------------------
  55. You've got several options. If you want to piggyback on top of an add/change
  56. form that Django automatically generates, you can attach arbitrary JavaScript
  57. modules to the page via the model's ``class Admin`` ``js`` parameter. That
  58. parameter is a list of URLs, as strings, pointing to JavaScript modules that
  59. will be included within the admin form via a ``<script>`` tag.
  60. If you want more flexibility than simply tweaking the auto-generated forms,
  61. feel free to write custom views for the admin. The admin is powered by Django
  62. itself, and you can write custom views that hook into the authentication
  63. system, check permissions and do whatever else they need to do.
  64. If you want to customize the look-and-feel of the admin interface, read the
  65. next question.
  66. The dynamically-generated admin site is ugly! How can I change it?
  67. ------------------------------------------------------------------
  68. We like it, but if you don't agree, you can modify the admin site's
  69. presentation by editing the CSS stylesheet and/or associated image files. The
  70. site is built using semantic HTML and plenty of CSS hooks, so any changes you'd
  71. like to make should be possible by editing the stylesheet. We've got a
  72. :doc:`guide to the CSS used in the admin </obsolete/admin-css>` to get you started.
  73. What browsers are supported for using the admin?
  74. ------------------------------------------------
  75. The admin provides a fully-functional experience to `YUI's A-grade`_ browsers,
  76. with the notable exception of IE6, which is not supported.
  77. There *may* be minor stylistic differences between supported browsers—for
  78. example, some browsers may not support rounded corners. These are considered
  79. acceptable variations in rendering.
  80. .. _YUI's A-grade: http://yuilibrary.com/yui/docs/tutorials/gbs/