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