| | 61 | Requiring user login |
|---|
| | 62 | ==================== |
|---|
| | 63 | |
|---|
| | 64 | You can restrict access to logged-in users with only a few extra lines of |
|---|
| | 65 | code. Simply add the following import to your URLconf:: |
|---|
| | 66 | |
|---|
| | 67 | from django.contrib.auth.decorators import login_required |
|---|
| | 68 | |
|---|
| | 69 | Then modify the URLconf so that the ``databrowse.site.root`` view is decorated |
|---|
| | 70 | with ``login_required``:: |
|---|
| | 71 | |
|---|
| | 72 | (r'^databrowse/(.*)', login_required(databrowse.site.root)), |
|---|
| | 73 | |
|---|
| | 74 | If you haven't already added support for user logins to your URLconf, as |
|---|
| | 75 | described in the `user authentication docs`_, then you will need to do so |
|---|
| | 76 | now with the following mapping:: |
|---|
| | 77 | |
|---|
| | 78 | (r'^accounts/login/$', 'django.contrib.auth.views.login'), |
|---|
| | 79 | |
|---|
| | 80 | The final step is to create the login form required by |
|---|
| | 81 | ``django.contrib.auth.views.login``. The `user authentication docs`_ |
|---|
| | 82 | provide full details and a sample template that can be used for this |
|---|
| | 83 | purpose. |
|---|
| | 84 | |
|---|