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