1
0
mirror of https://github.com/django/django.git synced 2024-12-23 17:46:27 +00:00
django/docs/databrowse.txt

87 lines
3.0 KiB
Plaintext
Raw Normal View History

==========
Databrowse
==========
Databrowse is a Django application that lets you browse your data.
As the Django admin dynamically creates an admin interface by introspecting
your models, Databrowse dynamically creates a rich, browsable Web site by
introspecting your models.
.. admonition:: Note
Databrowse is **very** new and is currently under active development. It
may change substantially before the next Django release.
With that said, it's easy to use, and it doesn't require writing any
code. So you can play around with it today, with very little investment in
time or coding.
How to use Databrowse
=====================
1. Point Django at the default Databrowse templates. There are two ways to
do this:
* Add ``'django.contrib.databrowse'`` to your ``INSTALLED_APPS``
setting. This will work if your ``TEMPLATE_LOADERS`` setting includes
the ``app_directories`` template loader (which is the case by
default). See the `template loader docs`_ for more.
* Otherwise, determine the full filesystem path to the
``django/contrib/databrowse/templates`` directory, and add that
directory to your ``TEMPLATE_DIRS`` setting.
2. Register a number of models with the Databrowse site::
from django.contrib import databrowse
from myapp.models import SomeModel, SomeOtherModel
databrowse.site.register(SomeModel)
databrowse.site.register(SomeOtherModel)
Note that you should register the model *classes*, not instances.
It doesn't matter where you put this, as long as it gets executed at
some point. A good place for it is in your URLconf file (``urls.py``).
3. Change your URLconf to import the ``databrowse`` module::
from django.contrib import databrowse
...and add the following line to your URLconf::
(r'^databrowse/(.*)', databrowse.site.root),
The prefix doesn't matter -- you can use ``databrowse/`` or ``db/`` or
whatever you'd like.
4. Run the Django server and visit ``/databrowse/`` in your browser.
Requiring user login
====================
You can restrict access to logged-in users with only a few extra lines of
code. Simply add the following import to your URLconf::
from django.contrib.auth.decorators import login_required
Then modify the URLconf so that the ``databrowse.site.root`` view is decorated
with ``login_required``::
(r'^databrowse/(.*)', login_required(databrowse.site.root)),
If you haven't already added support for user logins to your URLconf, as
described in the `user authentication docs`_, then you will need to do so
now with the following mapping::
(r'^accounts/login/$', 'django.contrib.auth.views.login'),
The final step is to create the login form required by
``django.contrib.auth.views.login``. The `user authentication docs`_
provide full details and a sample template that can be used for this
purpose.
.. _template loader docs: ../templates_python/#loader-types
.. _user authentication docs: ../authentication/