Ad

Login.html Cannot Be Rendered When Using Django Authentication System

I am using django default authentication system to do the login and logout. However, when the login button is clicked, my template login.html cannot be rendered; only the url is changed. Can anybody see why this is happening? BTW, I'm using django 1.6. thanks.

This is my project structure:

├── my_news
│   ├── __init__.py
│   ├── settings.pyc
│   ├── templates
│   │   └── registration
│   │       ├── logged_out.html
│   │       └── login.html
│   ├── urls.py
│   ├── wsgi.py
│   
├── manage.py
└── news
    ├── __init__.py
    ├── admin.py
    ├── models.py
    ├── templates
    │   ├── base.html
    │   └── news
    │       └── news_list.html
    ├── tests.p
    ├── views.py

My project level my_news/urls.py:

urlpatterns = patterns(
'',
url(r'^admin/', include(admin.site.urls)),
url(r'$', NewsListView.as_view(), name='home'),
url(r'^login/$', 'django.contrib.auth.views.login'),
url(r'^logout/$', 'django.contrib.auth.views.logout'),
)

base.html:

{{ user }}
{% if user.is_anonymous %}
<a target="_blank" rel="nofollow noreferrer" href="{% url 'django.contrib.auth.views.login' %}">login</a>
{% else %}
<a target="_blank" rel="nofollow noreferrer" href="{% url 'django.contrib.auth.views.logout' %}">logout</a>
{% endif %}
Ad

Answer

i found the problem. turns out i missed ^ character in my homepage url.

it was url(r'$', NewsListView.as_view(), name='home'), before and it should be this instead:

url(r'^$', NewsListView.as_view(), name='home'),.

Ad
source: stackoverflow.com
Ad