2007-04-16 21:56:10 +00:00
|
|
|
==========
|
|
|
|
Databrowse
|
|
|
|
==========
|
|
|
|
|
2008-08-23 22:25:40 +00:00
|
|
|
.. module:: django.contrib.databrowse
|
|
|
|
:synopsis: Databrowse is a Django application that lets you browse your data.
|
|
|
|
|
2011-09-22 04:10:02 +00:00
|
|
|
.. deprecated:: 1.4
|
|
|
|
This module has been deprecated.
|
|
|
|
|
2007-04-16 21:56:10 +00:00
|
|
|
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.
|
|
|
|
|
|
|
|
How to use Databrowse
|
|
|
|
=====================
|
|
|
|
|
|
|
|
1. Point Django at the default Databrowse templates. There are two ways to
|
|
|
|
do this:
|
|
|
|
|
2008-08-23 22:25:40 +00:00
|
|
|
* Add ``'django.contrib.databrowse'`` to your :setting:`INSTALLED_APPS`
|
|
|
|
setting. This will work if your :setting:`TEMPLATE_LOADERS` setting
|
|
|
|
includes the ``app_directories`` template loader (which is the case by
|
|
|
|
default). See the :ref:`template loader docs <template-loaders>` for
|
|
|
|
more.
|
2007-04-16 21:56:10 +00:00
|
|
|
|
|
|
|
* Otherwise, determine the full filesystem path to the
|
2008-11-02 20:43:20 +00:00
|
|
|
:file:`django/contrib/databrowse/templates` directory, and add that
|
2008-08-23 22:25:40 +00:00
|
|
|
directory to your :setting:`TEMPLATE_DIRS` setting.
|
2007-04-16 21:56:10 +00:00
|
|
|
|
|
|
|
2. Register a number of models with the Databrowse site::
|
|
|
|
|
|
|
|
from django.contrib import databrowse
|
2007-08-12 03:59:09 +00:00
|
|
|
from myapp.models import SomeModel, SomeOtherModel
|
2007-04-16 21:56:10 +00:00
|
|
|
|
|
|
|
databrowse.site.register(SomeModel)
|
|
|
|
databrowse.site.register(SomeOtherModel)
|
|
|
|
|
|
|
|
Note that you should register the model *classes*, not instances.
|
|
|
|
|
2008-08-23 22:25:40 +00:00
|
|
|
It doesn't matter where you put this, as long as it gets executed at some
|
2010-08-19 19:27:44 +00:00
|
|
|
point. A good place for it is in your :doc:`URLconf file
|
|
|
|
</topics/http/urls>` (``urls.py``).
|
2007-04-16 21:56:10 +00:00
|
|
|
|
2008-08-23 22:25:40 +00:00
|
|
|
3. Change your URLconf to import the :mod:`~django.contrib.databrowse` module::
|
2007-05-14 03:29:13 +00:00
|
|
|
|
|
|
|
from django.contrib import databrowse
|
|
|
|
|
|
|
|
...and add the following line to your URLconf::
|
2007-04-16 21:56:10 +00:00
|
|
|
|
|
|
|
(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.
|
2007-04-16 22:00:29 +00:00
|
|
|
|
2007-09-14 18:59:20 +00:00
|
|
|
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
|
|
|
|
|
2010-08-19 19:27:44 +00:00
|
|
|
Then modify the :doc:`URLconf </topics/http/urls>` so that the
|
2008-08-23 22:25:40 +00:00
|
|
|
:func:`databrowse.site.root` view is decorated with
|
|
|
|
:func:`django.contrib.auth.decorators.login_required`::
|
2007-09-14 18:59:20 +00:00
|
|
|
|
|
|
|
(r'^databrowse/(.*)', login_required(databrowse.site.root)),
|
|
|
|
|
2010-08-19 19:27:44 +00:00
|
|
|
If you haven't already added support for user logins to your :doc:`URLconf
|
|
|
|
</topics/http/urls>`, as described in the :doc:`user authentication docs
|
|
|
|
</ref/contrib/auth>`, then you will need to do so now with the following
|
2008-08-23 22:25:40 +00:00
|
|
|
mapping::
|
2007-09-14 18:59:20 +00:00
|
|
|
|
|
|
|
(r'^accounts/login/$', 'django.contrib.auth.views.login'),
|
|
|
|
|
|
|
|
The final step is to create the login form required by
|
2008-08-23 22:25:40 +00:00
|
|
|
:func:`django.contrib.auth.views.login`. The
|
2010-08-19 19:27:44 +00:00
|
|
|
:doc:`user authentication docs </ref/contrib/auth>` provide full details and a
|
2008-08-23 22:25:40 +00:00
|
|
|
sample template that can be used for this purpose.
|