{"title":"FAQ: The admin","version":"6.0","locale":"en","docname":"faq/admin","url":"/en/6.0/faq/admin/","canonical":"https://djangodocs.dev/en/6.0/faq/admin/","summary":"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. Link to this heading # The login cookie…","html":"<h1>FAQ: The admin<a class=\"heading-anchor\" href=\"#faq-the-admin\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<section id=\"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\">\n<h2>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.<a class=\"heading-anchor\" href=\"#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\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>The login cookie isn’t being set correctly, because the domain of the cookie\nsent out by Django doesn’t match the domain in your browser. Try setting the\n<a class=\"reference internal\" href=\"/en/6.0/ref/settings/#std-setting-SESSION_COOKIE_DOMAIN\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SESSION_COOKIE_DOMAIN</span></code></a> setting to match your domain. For example, if\nyou’re going to “<a class=\"reference external\" href=\"https://www.example.com/admin/\">https://www.example.com/admin/</a>” in your browser, set\n<code class=\"docutils literal notranslate\"><span class=\"pre\">SESSION_COOKIE_DOMAIN</span> <span class=\"pre\">=</span> <span class=\"pre\">'www.example.com'</span></code>.</p>\n</section>\n<section id=\"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\">\n<h2>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.<a class=\"heading-anchor\" href=\"#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\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>If you’re sure your username and password are correct, make sure your user\naccount has <a class=\"reference internal\" href=\"/en/6.0/ref/contrib/auth/#django.contrib.auth.models.User.is_active\" title=\"django.contrib.auth.models.User.is_active\"><code class=\"xref py py-attr docutils literal notranslate\"><span class=\"pre\">is_active</span></code></a> and\n<a class=\"reference internal\" href=\"/en/6.0/ref/contrib/auth/#django.contrib.auth.models.User.is_staff\" title=\"django.contrib.auth.models.User.is_staff\"><code class=\"xref py py-attr docutils literal notranslate\"><span class=\"pre\">is_staff</span></code></a> set to True. The admin site\nonly allows access to users with those two fields both set to True.</p>\n</section>\n<section id=\"how-do-i-automatically-set-a-field-s-value-to-the-user-who-last-edited-the-object-in-the-admin\">\n<h2>How do I automatically set a field’s value to the user who last edited the object in the admin?<a class=\"heading-anchor\" href=\"#how-do-i-automatically-set-a-field-s-value-to-the-user-who-last-edited-the-object-in-the-admin\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>The <a class=\"reference internal\" href=\"/en/6.0/ref/contrib/admin/#django.contrib.admin.ModelAdmin\" title=\"django.contrib.admin.ModelAdmin\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">ModelAdmin</span></code></a> class provides customization\nhooks that allow you to transform an object as it saved, using details from the\nrequest. By extracting the current user from the request, and customizing the\n<a class=\"reference internal\" href=\"/en/6.0/ref/contrib/admin/#django.contrib.admin.ModelAdmin.save_model\" title=\"django.contrib.admin.ModelAdmin.save_model\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">save_model()</span></code></a> hook, you can update an\nobject to reflect the user that edited it. See <a class=\"reference internal\" href=\"/en/6.0/ref/contrib/admin/#model-admin-methods\"><span class=\"std std-ref\">the documentation on\nModelAdmin methods</span></a> for an example.</p>\n</section>\n<section id=\"how-do-i-limit-admin-access-so-that-objects-can-only-be-edited-by-the-users-who-created-them\">\n<h2>How do I limit admin access so that objects can only be edited by the users who created them?<a class=\"heading-anchor\" href=\"#how-do-i-limit-admin-access-so-that-objects-can-only-be-edited-by-the-users-who-created-them\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>The <a class=\"reference internal\" href=\"/en/6.0/ref/contrib/admin/#django.contrib.admin.ModelAdmin\" title=\"django.contrib.admin.ModelAdmin\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">ModelAdmin</span></code></a> class also provides customization\nhooks that allow you to control the visibility and editability of objects in\nthe admin. Using the same trick of extracting the user from the request, the\n<a class=\"reference internal\" href=\"/en/6.0/ref/contrib/admin/#django.contrib.admin.ModelAdmin.get_queryset\" title=\"django.contrib.admin.ModelAdmin.get_queryset\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">get_queryset()</span></code></a> and\n<a class=\"reference internal\" href=\"/en/6.0/ref/contrib/admin/#django.contrib.admin.ModelAdmin.has_change_permission\" title=\"django.contrib.admin.ModelAdmin.has_change_permission\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">has_change_permission()</span></code></a> can be used to\ncontrol the visibility and editability of objects in the admin.</p>\n</section>\n<section id=\"my-admin-site-css-and-images-showed-up-fine-using-the-development-server-but-they-re-not-displaying-when-using-mod-wsgi\">\n<h2>My admin-site CSS and images showed up fine using the development server, but they’re not displaying when using mod_wsgi.<a class=\"heading-anchor\" href=\"#my-admin-site-css-and-images-showed-up-fine-using-the-development-server-but-they-re-not-displaying-when-using-mod-wsgi\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>See <a class=\"reference internal\" href=\"/en/6.0/howto/deployment/wsgi/modwsgi/#serving-the-admin-files\"><span class=\"std std-ref\">serving the admin files</span></a>\nin the “How to use Django with mod_wsgi” documentation.</p>\n</section>\n<section id=\"my-list-filter-contains-a-manytomanyfield-but-the-filter-doesn-t-display\">\n<h2>My “list_filter” contains a ManyToManyField, but the filter doesn’t display.<a class=\"heading-anchor\" href=\"#my-list-filter-contains-a-manytomanyfield-but-the-filter-doesn-t-display\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Django won’t bother displaying the filter for a <code class=\"docutils literal notranslate\"><span class=\"pre\">ManyToManyField</span></code> if there\nare no related objects.</p>\n<p>For example, if your <a class=\"reference internal\" href=\"/en/6.0/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_filter\" title=\"django.contrib.admin.ModelAdmin.list_filter\"><code class=\"xref py py-attr docutils literal notranslate\"><span class=\"pre\">list_filter</span></code></a>\nincludes <a class=\"reference internal\" href=\"/en/6.0/ref/contrib/sites/\"><span class=\"doc\">sites</span></a>, and there are no sites in your\ndatabase, it won’t display a “Site” filter. In that case, filtering by site\nwould be meaningless.</p>\n</section>\n<section id=\"some-objects-aren-t-appearing-in-the-admin\">\n<h2>Some objects aren’t appearing in the admin.<a class=\"heading-anchor\" href=\"#some-objects-aren-t-appearing-in-the-admin\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Inconsistent row counts may be caused by missing foreign key values or a\nforeign key field incorrectly set to <a class=\"reference internal\" href=\"/en/6.0/ref/models/fields/#django.db.models.Field.null\" title=\"django.db.models.Field.null\"><code class=\"xref py py-attr docutils literal notranslate\"><span class=\"pre\">null=False</span></code></a>. If you have a record with a\n<a class=\"reference internal\" href=\"/en/6.0/ref/models/fields/#django.db.models.ForeignKey\" title=\"django.db.models.ForeignKey\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">ForeignKey</span></code></a> pointing to a nonexistent object and\nthat foreign key is included is\n<a class=\"reference internal\" href=\"/en/6.0/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_display\" title=\"django.contrib.admin.ModelAdmin.list_display\"><code class=\"xref py py-attr docutils literal notranslate\"><span class=\"pre\">list_display</span></code></a>, the record will not be\nshown in the admin changelist because the Django model is declaring an\nintegrity constraint that is not implemented at the database level.</p>\n</section>\n<section id=\"how-can-i-customize-the-functionality-of-the-admin-interface\">\n<h2>How can I customize the functionality of the admin interface?<a class=\"heading-anchor\" href=\"#how-can-i-customize-the-functionality-of-the-admin-interface\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>You’ve got several options. If you want to piggyback on top of an add/change\nform that Django automatically generates, you can attach arbitrary JavaScript\nmodules to the page via the model’s class Admin <a class=\"reference internal\" href=\"/en/6.0/ref/contrib/admin/#modeladmin-asset-definitions\"><span class=\"std std-ref\">js parameter</span></a>. That parameter is a list of URLs, as strings,\npointing to JavaScript modules that will be included within the admin form via\na <code class=\"docutils literal notranslate\"><span class=\"pre\">&lt;script&gt;</span></code> tag.</p>\n<p>If you want more flexibility than is feasible by tweaking the auto-generated\nforms, feel free to write custom views for the admin. The admin is powered by\nDjango itself, and you can write custom views that hook into the authentication\nsystem, check permissions and do whatever else they need to do.</p>\n<p>If you want to customize the look-and-feel of the admin interface, read the\nnext question.</p>\n</section>\n<section id=\"the-dynamically-generated-admin-site-is-ugly-how-can-i-change-it\">\n<h2>The dynamically-generated admin site is ugly! How can I change it?<a class=\"heading-anchor\" href=\"#the-dynamically-generated-admin-site-is-ugly-how-can-i-change-it\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>We like it, but if you don’t agree, you can modify the admin site’s\npresentation by editing the CSS stylesheet and/or associated image files. The\nsite is built using semantic HTML and plenty of CSS hooks, so any changes you’d\nlike to make should be possible by editing the stylesheet.</p>\n</section>\n<section id=\"what-browsers-are-supported-for-using-the-admin\">\n<span id=\"admin-browser-support\"></span><h2>What browsers are supported for using the admin?<a class=\"heading-anchor\" href=\"#what-browsers-are-supported-for-using-the-admin\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>The admin provides a fully-functional experience to the recent versions of\nmodern, web standards compliant browsers. On desktop this means Chrome, Edge,\nFirefox, Opera, Safari, and others.</p>\n<p>On mobile and tablet devices, the admin provides a responsive experience for\nweb standards compliant browsers. This includes the major browsers on both\nAndroid and iOS.</p>\n<p>Depending on feature support, there <em>may</em> be minor stylistic differences\nbetween browsers. These are considered acceptable variations in rendering.</p>\n</section>\n<section id=\"what-assistive-technologies-are-supported-for-using-the-admin\">\n<h2>What assistive technologies are supported for using the admin?<a class=\"heading-anchor\" href=\"#what-assistive-technologies-are-supported-for-using-the-admin\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>The admin is intended to be compatible with a wide range of assistive\ntechnologies, but there are currently many blockers. The support target is all\nlatest versions of major assistive technologies, including Dragon, JAWS, NVDA,\nOrca, TalkBack, Voice Control, VoiceOver iOS, VoiceOver macOS, Windows Contrast\nThemes, ZoomText, and screen magnifiers.</p>\n</section>","rootId":"faq-the-admin","toc":[{"title":"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.","anchor":"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","children":[]},{"title":"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.","anchor":"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","children":[]},{"title":"How do I automatically set a field’s value to the user who last edited the object in the admin?","anchor":"how-do-i-automatically-set-a-field-s-value-to-the-user-who-last-edited-the-object-in-the-admin","children":[]},{"title":"How do I limit admin access so that objects can only be edited by the users who created them?","anchor":"how-do-i-limit-admin-access-so-that-objects-can-only-be-edited-by-the-users-who-created-them","children":[]},{"title":"My admin-site CSS and images showed up fine using the development server, but they’re not displaying when using mod_wsgi.","anchor":"my-admin-site-css-and-images-showed-up-fine-using-the-development-server-but-they-re-not-displaying-when-using-mod-wsgi","children":[]},{"title":"My “list_filter” contains a ManyToManyField, but the filter doesn’t display.","anchor":"my-list-filter-contains-a-manytomanyfield-but-the-filter-doesn-t-display","children":[]},{"title":"Some objects aren’t appearing in the admin.","anchor":"some-objects-aren-t-appearing-in-the-admin","children":[]},{"title":"How can I customize the functionality of the admin interface?","anchor":"how-can-i-customize-the-functionality-of-the-admin-interface","children":[]},{"title":"The dynamically-generated admin site is ugly! How can I change it?","anchor":"the-dynamically-generated-admin-site-is-ugly-how-can-i-change-it","children":[]},{"title":"What browsers are supported for using the admin?","anchor":"what-browsers-are-supported-for-using-the-admin","children":[]},{"title":"What assistive technologies are supported for using the admin?","anchor":"what-assistive-technologies-are-supported-for-using-the-admin","children":[]}],"breadcrumbs":[{"docname":"faq/index","title":"Django FAQ","url":"/en/6.0/faq/"}],"prev":{"docname":"faq/models","title":"FAQ: Databases and models","url":"/en/6.0/faq/models/"},"next":{"docname":"faq/contributing","title":"FAQ: Contributing code","url":"/en/6.0/faq/contributing/"},"formats":{"html":"/en/6.0/faq/admin/","markdown":"/en/6.0/faq/admin.md","json":"/en/6.0/faq/admin.json"},"source":"https://github.com/django/django/blob/stable/6.0.x/docs/faq/admin.txt","official":"https://docs.djangoproject.com/en/6.0/faq/admin/","inVersions":["dev","6.1","6.0","5.2","5.1","5.0","4.2","4.1","4.0","3.2","3.1","3.0","2.2","2.1","2.0","1.11","1.10","1.9","1.8"],"inLocales":["en","sv","zh-hans","ga","fr","ja","id","it","pt-br","ko","es","el","pl"]}