1
.. _ref-contrib-databrowse:
7
.. module:: django.contrib.databrowse
8
:synopsis: Databrowse is a Django application that lets you browse your data.
10
Databrowse is a Django application that lets you browse your data.
12
As the Django admin dynamically creates an admin interface by introspecting
13
your models, Databrowse dynamically creates a rich, browsable Web site by
14
introspecting your models.
18
Databrowse is **very** new and is currently under active development. It
19
may change substantially before the next Django release.
21
With that said, it's easy to use, and it doesn't require writing any
22
code. So you can play around with it today, with very little investment in
28
1. Point Django at the default Databrowse templates. There are two ways to
31
* Add ``'django.contrib.databrowse'`` to your :setting:`INSTALLED_APPS`
32
setting. This will work if your :setting:`TEMPLATE_LOADERS` setting
33
includes the ``app_directories`` template loader (which is the case by
34
default). See the :ref:`template loader docs <template-loaders>` for
37
* Otherwise, determine the full filesystem path to the
38
`:file:`django/contrib/databrowse/templates` directory, and add that
39
directory to your :setting:`TEMPLATE_DIRS` setting.
41
2. Register a number of models with the Databrowse site::
43
from django.contrib import databrowse
44
from myapp.models import SomeModel, SomeOtherModel
46
databrowse.site.register(SomeModel)
47
databrowse.site.register(SomeOtherModel)
49
Note that you should register the model *classes*, not instances.
51
It doesn't matter where you put this, as long as it gets executed at some
52
point. A good place for it is in your :ref:`URLconf file
53
<topics-http-urls>` (``urls.py``).
55
3. Change your URLconf to import the :mod:`~django.contrib.databrowse` module::
57
from django.contrib import databrowse
59
...and add the following line to your URLconf::
61
(r'^databrowse/(.*)', databrowse.site.root),
63
The prefix doesn't matter -- you can use ``databrowse/`` or ``db/`` or
66
4. Run the Django server and visit ``/databrowse/`` in your browser.
71
You can restrict access to logged-in users with only a few extra lines of
72
code. Simply add the following import to your URLconf::
74
from django.contrib.auth.decorators import login_required
76
Then modify the :ref:`URLconf <topics-http-urls>` so that the
77
:func:`databrowse.site.root` view is decorated with
78
:func:`django.contrib.auth.decorators.login_required`::
80
(r'^databrowse/(.*)', login_required(databrowse.site.root)),
82
If you haven't already added support for user logins to your :ref:`URLconf
83
<topics-http-urls>`, as described in the :ref:`user authentication docs
84
<ref-contrib-auth>`, then you will need to do so now with the following
87
(r'^accounts/login/$', 'django.contrib.auth.views.login'),
89
The final step is to create the login form required by
90
:func:`django.contrib.auth.views.login`. The
91
:ref:`user authentication docs <ref-contrib-auth>` provide full details and a
92
sample template that can be used for this purpose.