Ad

How Does Django Know Where To Load Login.html

- 1 answer

I have used the following steps to create a login page.

1> create the urls.py

urlpatterns = patterns('',
(r'^$', main_page),
(r'^login/$', 'django.contrib.auth.views.login'),
)

2> create registration/login.html

3> load http://127.0.0.1:8000/login/ then I see the created login.html.

Also my directory structure is as follows:

.
├── bookmarks
│   ├── forms.py
│   ├── __init__.py
│   ├── models.py
│   ├── tests.py
│   └── views.py
├── bookmarksdb
├── __init__.py
├── manage.py
├── settings.py
├── site_media
│   └── style.css
├── templates
│   ├── base.html
│   ├── main_page.html
│   ├── registration
│   │   ├── login.html
│   │   ├── logout_success.html
│   │   ├── register.html
│   │   └── register_success.html
│   ├── user_page.html
└── urls.py

Question> How does django know to connect the http://127.0.0.1:8000/login/ with template\registration\login.html?

Thank you

Ad

Answer

if you look in django.contrib.auth.views.py you'll find

def login(request, template_name='registration/login.html'),
      redirect_field_name=REDIRECT_FIELD_NAME,
      authentication_form=AuthenticationForm,
      current_app=None, extra_context=None):
"""
Displays the login form and handles the login action.
"""

it's simply the default template path, which you can override should you wish

Ad
source: stackoverflow.com
Ad