databrowse.txt 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. ==========
  2. Databrowse
  3. ==========
  4. .. module:: django.contrib.databrowse
  5. :synopsis: Databrowse is a Django application that lets you browse your data.
  6. .. deprecated:: 1.4
  7. This module has been deprecated.
  8. Databrowse is a Django application that lets you browse your data.
  9. As the Django admin dynamically creates an admin interface by introspecting
  10. your models, Databrowse dynamically creates a rich, browsable Web site by
  11. introspecting your models.
  12. How to use Databrowse
  13. =====================
  14. 1. Point Django at the default Databrowse templates. There are two ways to
  15. do this:
  16. * Add ``'django.contrib.databrowse'`` to your :setting:`INSTALLED_APPS`
  17. setting. This will work if your :setting:`TEMPLATE_LOADERS` setting
  18. includes the ``app_directories`` template loader (which is the case by
  19. default). See the :ref:`template loader docs <template-loaders>` for
  20. more.
  21. * Otherwise, determine the full filesystem path to the
  22. :file:`django/contrib/databrowse/templates` directory, and add that
  23. directory to your :setting:`TEMPLATE_DIRS` setting.
  24. 2. Register a number of models with the Databrowse site::
  25. from django.contrib import databrowse
  26. from myapp.models import SomeModel, SomeOtherModel
  27. databrowse.site.register(SomeModel)
  28. databrowse.site.register(SomeOtherModel)
  29. Note that you should register the model *classes*, not instances.
  30. It doesn't matter where you put this, as long as it gets executed at some
  31. point. A good place for it is in your :doc:`URLconf file
  32. </topics/http/urls>` (``urls.py``).
  33. 3. Change your URLconf to import the :mod:`~django.contrib.databrowse` module::
  34. from django.contrib import databrowse
  35. ...and add the following line to your URLconf::
  36. (r'^databrowse/(.*)', databrowse.site.root),
  37. The prefix doesn't matter -- you can use ``databrowse/`` or ``db/`` or
  38. whatever you'd like.
  39. 4. Run the Django server and visit ``/databrowse/`` in your browser.
  40. Requiring user login
  41. ====================
  42. You can restrict access to logged-in users with only a few extra lines of
  43. code. Simply add the following import to your URLconf::
  44. from django.contrib.auth.decorators import login_required
  45. Then modify the :doc:`URLconf </topics/http/urls>` so that the
  46. :func:`databrowse.site.root` view is decorated with
  47. :func:`django.contrib.auth.decorators.login_required`::
  48. (r'^databrowse/(.*)', login_required(databrowse.site.root)),
  49. If you haven't already added support for user logins to your :doc:`URLconf
  50. </topics/http/urls>`, as described in the :doc:`user authentication docs
  51. </ref/contrib/auth>`, then you will need to do so now with the following
  52. mapping::
  53. (r'^accounts/login/$', 'django.contrib.auth.views.login'),
  54. The final step is to create the login form required by
  55. :func:`django.contrib.auth.views.login`. The
  56. :doc:`user authentication docs </ref/contrib/auth>` provide full details and a
  57. sample template that can be used for this purpose.