Django 1.10.2 error "NoReverseMatch at " ,"Reverse for 'django.contrib.auth.views.login' with arguments '()' and keyword arguments '{}' not found."
Question: I am new to python & Django. I am getting one error and have absolutely no
idea how to solve it. Any help will be appreciated. [![enter image description
here](https://i.stack.imgur.com/4Cw94.png)](https://i.stack.imgur.com/4Cw94.png)

    
    
    from django.shortcuts import render
    # Create your views here.
    #log/views.py
    from django.shortcuts import render
    from django.contrib.auth.decorators import login_required
    # Create your views here.
    # this login required decorator is to not allow to any
    # view without authenticating
    @login_required(login_url="login/")
    def home(request):
         return render(request,"home.html")
    

The code in urls.py is,

    
    
    from django.conf.urls import include,url
    from django.contrib import admin
    from django.contrib.auth import views as auth_views
    from log.forms import LoginForm
    urlpatterns = [
     url(r'^admin/', admin.site.urls),
     url(r'', include('log.urls')),
     url(r'^login/$', auth_views.login ,{'template_name':   'login.html','authentication_form': LoginForm}),
     url(r'^logout/$', auth_views.logout, {'next_page': '/login'}),
     ]
    

The code in login.html is,

    
    
    {% extends 'base.html' %}
    
    
    {% block content %}
        {% if form.errors %}
    
    <p>Your username and password didn't match. Please try again.</p>
    {% endif %}
    
    {% if next %}
        {% if user.is_authenticated %}
    
    <p>Your account doesn't have access to this page. To proceed,
        please login with an account that has access.</p>
        {% else %}
    
    <p>Please login to see this page.</p>
        {% endif %}
    {% endif %}
    
    <div class="container">
        <div class="row">
            <div class="col-md-4 col-md-offset-4">
                <div class="login-panel panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title">Please Sign In</h3>
                    </div>
                    <div class="panel-body">
                        <form method="post" action="{% url 'django.contrib.auth.views.login' %}">
    {% csrf_token %}
    
                            <p class="bs-component">
                                <table>
                                    <tr>
                                        <td>{{ form.username.label_tag }}</td>
                                        <td>{{ form.username }}</td>
                                    </tr>
                                    <tr>
                                        <td>{{ form.password.label_tag }}</td>
                                        <td>{{ form.password }}</td>
                                    </tr>
                                </table>
                            </p>
                            <p class="bs-component">
                                <center>
                                    <input class="btn btn-success btn-sm" type="submit" value="login" />
                                </center>
                            </p>
                            <input type="hidden" name="next" value="{{ next }}" />
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    {% endblock %}
    
    {% block javascript %}
    
    
    <script>
    {% if not user.is_authenticated %}
    $("ul.nav.navbar-nav.navbar-right").css("display","none");
    {% endif %}
    </script>
    
    {% endblock %}

Hope this much info will do....


Answer: Add a `name` to the login _url pattern_ :

    
    
    kwargs = {'template_name': 'login.html','authentication_form': LoginForm}
    ...
    url(r'^login/$', auth_views.login, kwargs=kwargs, name='login'),
    #                                                  ^^^^
    

and then use that `name` in your template:

    
    
    <form method="post" action="{% url 'login' %}">
    

