0

I am getting an error NoReverseMatch at /user/login/ when i click on the page /users/login. Below is how my code looks

urls.py

  url(r'^$', 'views.homepage', name='home'),
  url(r'^user/login/$', 'coolstuff.views.login_view'),

views.py

def login_view(request):
   if request.method == 'POST':
      username = request.POST['email']
      password = request.POST['password']
      user = authenticate(username=username, password=password)
      if user is not None and user.is_active:
         login(request, user)
         return HttpResponseRedirect(request.GET.get("next"))
      else:
          login_error = "Your username and/or password are incorrect."
          return HttpResponseRedirect(reverse('views.homepage', kwargs={'login_error': login_error}))


def homepage(request, login_error=''):
    return render_to_response(homepage.html,
         {'login_error': login_error,},
         context_instance=RequestContext(request))

So, i want to pass the login_error variable only when the user types in wrong username or password. In any other case, the homepage gets called with no login_error. I am trying to pass login_error as an extra variable into the view function but getting the error NoReverseMatch at /user/login/.

How can i solve this ?

Dev
  • 1,529
  • 4
  • 24
  • 36

1 Answers1

2

Your view doesn't take any arguments in the url pattern which is why it is failing. You need to use the messages framework which is designed for this use case.

Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284