admin.txt 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. ==============
  2. FAQ: The admin
  3. ==============
  4. 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.
  5. ===========================================================================================================================
  6. The login cookie isn't being set correctly, because the domain of the cookie
  7. sent out by Django doesn't match the domain in your browser. Try setting the
  8. :setting:`SESSION_COOKIE_DOMAIN` setting to match your domain. For example, if
  9. you're going to "https://www.example.com/admin/" in your browser, set
  10. ``SESSION_COOKIE_DOMAIN = 'www.example.com'``.
  11. 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.
  12. ===========================================================================================================================================================
  13. If you're sure your username and password are correct, make sure your user
  14. account has :attr:`~django.contrib.auth.models.User.is_active` and
  15. :attr:`~django.contrib.auth.models.User.is_staff` set to True. The admin site
  16. only allows access to users with those two fields both set to True.
  17. How do I automatically set a field's value to the user who last edited the object in the admin?
  18. ===============================================================================================
  19. The :class:`~django.contrib.admin.ModelAdmin` class provides customization hooks
  20. that allow you to transform an object as it saved, using details from the
  21. request. By extracting the current user from the request, and customizing the
  22. :meth:`~django.contrib.admin.ModelAdmin.save_model` hook, you can update an
  23. object to reflect the user that edited it. See :ref:`the documentation on
  24. ModelAdmin methods <model-admin-methods>` for an example.
  25. How do I limit admin access so that objects can only be edited by the users who created them?
  26. =============================================================================================
  27. The :class:`~django.contrib.admin.ModelAdmin` class also provides customization
  28. hooks that allow you to control the visibility and editability of objects in the
  29. admin. Using the same trick of extracting the user from the request, the
  30. :meth:`~django.contrib.admin.ModelAdmin.get_queryset` and
  31. :meth:`~django.contrib.admin.ModelAdmin.has_change_permission` can be used to
  32. control the visibility and editability of objects in the admin.
  33. My admin-site CSS and images showed up fine using the development server, but they're not displaying when using mod_wsgi.
  34. =========================================================================================================================
  35. See :ref:`serving the admin files <serving-the-admin-files>`
  36. in the "How to use Django with mod_wsgi" documentation.
  37. My "list_filter" contains a ManyToManyField, but the filter doesn't display.
  38. ============================================================================
  39. Django won't bother displaying the filter for a ``ManyToManyField`` if there
  40. are no related objects.
  41. For example, if your :attr:`~django.contrib.admin.ModelAdmin.list_filter`
  42. includes :doc:`sites </ref/contrib/sites>`, and there are no sites in your
  43. database, it won't display a "Site" filter. In that case, filtering by site
  44. would be meaningless.
  45. Some objects aren't appearing in the admin.
  46. ===========================================
  47. Inconsistent row counts may be caused by missing foreign key values or a
  48. foreign key field incorrectly set to :attr:`null=False
  49. <django.db.models.Field.null>`. If you have a record with a
  50. :class:`~django.db.models.ForeignKey` pointing to a nonexistent object and
  51. that foreign key is included is
  52. :attr:`~django.contrib.admin.ModelAdmin.list_display`, the record will not be
  53. shown in the admin changelist because the Django model is declaring an
  54. integrity constraint that is not implemented at the database level.
  55. How can I customize the functionality of the admin interface?
  56. =============================================================
  57. You've got several options. If you want to piggyback on top of an add/change
  58. form that Django automatically generates, you can attach arbitrary JavaScript
  59. modules to the page via the model's class Admin :ref:`js parameter
  60. <modeladmin-asset-definitions>`. That parameter is a list of URLs, as strings,
  61. pointing to JavaScript modules that will be included within the admin form via
  62. a ``<script>`` tag.
  63. If you want more flexibility than is feasible by tweaking the auto-generated
  64. forms, feel free to write custom views for the admin. The admin is powered by
  65. Django itself, and you can write custom views that hook into the authentication
  66. system, check permissions and do whatever else they need to do.
  67. If you want to customize the look-and-feel of the admin interface, read the
  68. next question.
  69. The dynamically-generated admin site is ugly! How can I change it?
  70. ==================================================================
  71. We like it, but if you don't agree, you can modify the admin site's
  72. presentation by editing the CSS stylesheet and/or associated image files. The
  73. site is built using semantic HTML and plenty of CSS hooks, so any changes you'd
  74. like to make should be possible by editing the stylesheet.
  75. .. _admin-browser-support:
  76. What browsers are supported for using the admin?
  77. ================================================
  78. The admin provides a fully-functional experience to the recent versions of
  79. modern, web standards compliant browsers. On desktop this means Chrome, Edge,
  80. Firefox, Opera, Safari, and others.
  81. On mobile and tablet devices, the admin provides a responsive experience for
  82. web standards compliant browsers. This includes the major browsers on both
  83. Android and iOS.
  84. Depending on feature support, there *may* be minor stylistic differences
  85. between browsers. These are considered acceptable variations in rendering.
  86. What assistive technologies are supported for using the admin?
  87. ==============================================================
  88. The admin is intended to be compatible with a wide range of assistive
  89. technologies, but there are currently many blockers. The support target is all
  90. latest versions of major assistive technologies, including Dragon, JAWS, NVDA,
  91. Orca, TalkBack, Voice Control, VoiceOver iOS, VoiceOver macOS, Windows Contrast
  92. Themes, ZoomText, and screen magnifiers.