quickstart.rst 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. Quickstart
  2. ==========
  3. Follow these instructions to get set up with a basic install of
  4. django-browserid:
  5. Installation
  6. ------------
  7. You can use pip to install django-browserid and requirements:
  8. .. code-block:: sh
  9. $ pip install django-browserid
  10. Configuration
  11. -------------
  12. After installation, you'll need to configure your site to use django-browserid.
  13. Start by making the following changes to your ``settings.py`` file:
  14. .. code-block:: python
  15. # Add 'django_browserid' to INSTALLED_APPS.
  16. INSTALLED_APPS = (
  17. # ...
  18. 'django.contrib.auth',
  19. 'django_browserid', # Load after auth
  20. # ...
  21. )
  22. # Add the django_browserid authentication backend.
  23. AUTHENTICATION_BACKENDS = (
  24. # ...
  25. 'django.contrib.auth.backends.ModelBackend',
  26. 'django_browserid.auth.BrowserIDBackend',
  27. # ...
  28. )
  29. Next, edit your ``urls.py`` file and add the following:
  30. .. code-block:: python
  31. urlpatterns = patterns('',
  32. # ...
  33. (r'', include('django_browserid.urls')),
  34. # ...
  35. )
  36. .. note:: The django-browserid urlconf *must not* have a regex with the
  37. include. Use a blank string, as shown above.
  38. Finally, you'll need to add the login button and info tag to your Django
  39. templates, along with the CSS and JS files necessary to make it work:
  40. .. code-block:: html+django
  41. {% load browserid %}
  42. <html>
  43. <head>
  44. {% browserid_css %}
  45. </head>
  46. <body>
  47. {% browserid_info %}
  48. {% if user.is_authenticated %}
  49. <p>Current user: {{ user.email }}</p>
  50. {% browserid_logout text='Logout' %}
  51. {% else %}
  52. {% browserid_login text='Login' color='dark' %}
  53. {% endif %}
  54. <script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
  55. {% browserid_js %}
  56. </body>
  57. </html>
  58. .. note:: ``api.js`` and ``browserid.js`` require `jQuery`_ 1.8 or higher.
  59. .. note:: The ``browserid_info`` tag is required on any page that users can log
  60. in from. It's recommended to put it just below the ``<body>`` tag.
  61. And that's it! You can now log into your site using Persona!
  62. Once you're ready, you should check out :doc:`how to customize django-browserid
  63. </user/customization>` to your liking.
  64. .. _jQuery: http://jquery.com/
  65. Note for Jinja2 / Jingo Users
  66. -----------------------------
  67. If you're using Jinja2_ via jingo_, here's a version of the example above
  68. written in Jinja2:
  69. .. code-block:: jinja
  70. <html>
  71. <head>
  72. {{ browserid_css() }}
  73. </head>
  74. <body>
  75. {{ browserid_info() }}
  76. {% if user.is_authenticated() %}
  77. <p>Current user: {{ user.email }}</p>
  78. {{ browserid_logout(text='Logout') }}
  79. {% else %}
  80. {{ browserid_login(text='Login', color='dark') }}
  81. {% endif %}
  82. <script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
  83. {{ browserid_js() }}
  84. </body>
  85. </html>
  86. .. _Jinja2: http://jinja.pocoo.org/
  87. .. _jingo: https://github.com/jbalogh/jingo