databrowse.txt 3.3 KB

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