Reputation: 7967
I am facing an error when I try to use the login
function from django.contrib.auth.views
. The error I get is Reverse for '' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
. There are similar questions on SO on the same topic but all relate to a function. Here, in the error message the error string does not mention any function which has me confused.
Below are the settings.py and urls.py file. let me know if any other information is required.
urls.py
from django.conf.urls import patterns, include, url
from django.conf import settings
from django.conf.urls.static import static
from django.contrib.auth import views as auth_views
from django.contrib import admin
admin.autodiscover()
from bootcamp.core import views as core_views
from bootcamp.authentication import views as bootcamp_auth_views
from bootcamp.activities import views as activities_views
from bootcamp.search import views as search_views
urlpatterns = [
url(r'^$', core_views.home, name='home'),
url(r'^login', auth_views.login, {'template_name': 'core/cover.html'}, name='login'),
url(r'^logout', auth_views.logout, {'next_page': '/'}, name='logout'),
url(r'^signup/$', bootcamp_auth_views.signup, name='signup'),
url(r'^settings/$', core_views.settings, name='settings'),
url(r'^settings/picture/$', core_views.picture, name='picture'),
url(r'^settings/upload_picture/$', core_views.upload_picture, name='upload_picture'),
url(r'^settings/save_uploaded_picture/$', core_views.save_uploaded_picture, name='save_uploaded_picture'),
url(r'^settings/password/$', core_views.password, name='password'),
url(r'^network/$', core_views.network, name='network'),
url(r'^feeds/', include('bootcamp.feeds.urls')),
url(r'^questions/', include('bootcamp.questions.urls')),
url(r'^articles/', include('bootcamp.articles.urls')),
url(r'^messages/', include('bootcamp.messenger.urls')),
url(r'^notifications/$', activities_views.notifications, name='notifications'),
url(r'^notifications/last/$', activities_views.last_notifications, name='last_notifications'),
url(r'^notifications/check/$', activities_views.check_notifications, name='check_notifications'),
url(r'^search/$', search_views.search, name='search'),
url(r'^(?P<username>[^/]+)/$', core_views.profile, name='profile'),
url(r'^i18n/', include('django.conf.urls.i18n', namespace='i18n')),
url(r'^admin/', include(admin.site.urls)),
]
settings.py
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.admin',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
'bootcamp.activities',
'bootcamp.articles',
'bootcamp.authentication',
'bootcamp.core',
'bootcamp.feeds',
'bootcamp.messenger',
'bootcamp.questions',
'bootcamp.search',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [PROJECT_DIR.child('templates')],
'APP_DIRS': True,
'OPTIONS': {
'debug':DEBUG,
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
EDIT
Adding the template core/cover.html
{% extends 'base.html' %}
{% load staticfiles %}
{% load i18n %}
{% block head %}
<link href="{% static 'css/cover.css' %}" rel="stylesheet">
{% endblock head %}
{% block body %}
<div class="cover">
<h1 class="logo">muHUB</h1>
{% if form.non_field_errors %}
{% for error in form.non_field_errors %}
<div class="alert alert-danger alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
{{ error }}
</div>
{% endfor %}
{% endif %}
<div class="login">
<h2>{% trans 'Log in' %}</h2>
<form method="post" action="{% url 'login' %}" role="form">
{% csrf_token %}
<div class="form-group{% if form.username.errors %} has-error{% endif %}">
<label for="username">{% trans 'Username' %}</label>
<input type="text" class="form-control" id="username" name="username">
{% for error in form.username.errors %}
<label class="control-label">{{ error }}</label>
{% endfor %}
</div>
<div class="form-group{% if form.password.errors %} has-error{% endif %}">
<label for="password">{% trans 'Password' %}</label>
<input type="password" class="form-control" id="password" name="password">
{% for error in form.password.errors %}
<label class="control-label">{{ error }}</label>
{% endfor %}
</div>
<div class="form-group">
<button type="submit" class="btn btn-default">{% trans 'Log in' %}</button>
<a href="{% url 'signup' %}" class="btn btn-link">{% trans 'Sign up for muHUB' %}</a>
</div>
</form>
</div>
</div>
{% endblock body %}
EDIT 2
Adding the traceback
Traceback:
File "C:\Anaconda2\lib\site-packages\django\core\handlers\base.py" in get_response
149. response = self.process_exception_by_middleware(e, request)
File "C:\Anaconda2\lib\site-packages\django\core\handlers\base.py" in get_response
147. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Anaconda2\lib\site-packages\django\contrib\auth\views.py" in inner
49. return func(*args, **kwargs)
File "C:\Anaconda2\lib\site-packages\django\views\decorators\debug.py" in sensitive_post_parameters_wrapper
76. return view(request, *args, **kwargs)
File "C:\Anaconda2\lib\site-packages\django\utils\decorators.py" in _wrapped_view
149. response = view_func(request, *args, **kwargs)
File "C:\Anaconda2\lib\site-packages\django\views\decorators\cache.py" in _wrapped_view_func
57. response = view_func(request, *args, **kwargs)
File "C:\Anaconda2\lib\site-packages\django\contrib\auth\views.py" in login
73. redirect_to = resolve_url(settings.LOGIN_REDIRECT_URL)
File "C:\Anaconda2\lib\site-packages\django\shortcuts.py" in resolve_url
204. return urlresolvers.reverse(to, args=args, kwargs=kwargs)
File "C:\Anaconda2\lib\site-packages\django\core\urlresolvers.py" in reverse
600. return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)))
File "C:\Anaconda2\lib\site-packages\django\core\urlresolvers.py" in _reverse_with_prefix
508. (lookup_view_s, args, kwargs, len(patterns), patterns))
Exception Type: NoReverseMatch at /login/
Exception Value: Reverse for '' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
Upvotes: 2
Views: 2515
Reputation: 53744
The error is in your LOGIN_REDIRECT_URL, this the only code in the stacktrace that has a connection to your own code.
File "C:\Anaconda2\lib\site-packages\django\contrib\auth\views.py" in login
73. redirect_to = resolve_url(settings.LOGIN_REDIRECT_URL)
I suspect that your login redirect url is constructed with the help of reverse or it's improperly set.
Upvotes: 1