I am getting the below error message and I couldn't see a way to fix it.
NoReverseMatch at /login/
Reverse for '' not found. '' is not a valid view function or pattern name.
Request Method: GET
Request URL: http://127.0.0.1:8000/login/?next=/
Django Version: 2.0.1
Exception Type: NoReverseMatch
Exception Value:
Reverse for '' not found. '' is not a valid view function or pattern name.
Exception Location: C:\Users\gokul\Desktop\TESTING\data\lib\site-packages\django\urls\resolvers.py in _reverse_with_prefix, line 632
Python Executable: C:\Users\gokul\Desktop\TESTING\data\Scripts\python.exe
Python Version: 3.5.2
Python Path:
['C:\\Users\\gokul\\Desktop\\TESTING\\data\\tagent',
'C:\\Users\\gokul\\Desktop\\TESTING\\data\\Scripts\\python35.zip',
'C:\\Users\\gokul\\Desktop\\TESTING\\data\\DLLs',
'C:\\Users\\gokul\\Desktop\\TESTING\\data\\lib',
'C:\\Users\\gokul\\Desktop\\TESTING\\data\\Scripts',
'c:\\program files\\python35\\Lib',
'c:\\program files\\python35\\DLLs',
'C:\\Users\\gokul\\Desktop\\TESTING\\data',
'C:\\Users\\gokul\\Desktop\\TESTING\\data\\lib\\site-packages']
> python manage.py runserver
Performing system checks...
System check identified no issues (0 silenced).
January 17, 2018 - 17:21:56
Django version 2.0.1, using settings 'tagent.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
[17/Jan/2018 17:22:03] "GET / HTTP/1.1" 302 0
Internal Server Error: /login/
Traceback (most recent call last):
File "C:\Users\gokul\Desktop\TESTING\data\lib\site-packages\django\core\handlers\exception.py", line 35, in inner
response = get_response(request)
File "C:\Users\gokul\Desktop\TESTING\data\lib\site-packages\django\core\handlers\base.py", line 158, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\gokul\Desktop\TESTING\data\lib\site-packages\django\core\handlers\base.py", line 156, in _get_response
response = response.render()
File "C:\Users\gokul\Desktop\TESTING\data\lib\site-packages\django\template\response.py", line 106, in render
self.content = self.rendered_content
File "C:\Users\gokul\Desktop\TESTING\data\lib\site-packages\django\template\response.py", line 83, in rendered_content
content = template.render(context, self._request)
File "C:\Users\gokul\Desktop\TESTING\data\lib\site-packages\django\template\backends\django.py", line 61, in render
return self.template.render(context)
File "C:\Users\gokul\Desktop\TESTING\data\lib\site-packages\django\template\base.py", line 175, in render
return self._render(context)
File "C:\Users\gokul\Desktop\TESTING\data\lib\site-packages\django\template\base.py", line 167, in _render
return self.nodelist.render(context)
File "C:\Users\gokul\Desktop\TESTING\data\lib\site-packages\django\template\base.py", line 943, in render
bit = node.render_annotated(context)
File "C:\Users\gokul\Desktop\TESTING\data\lib\site-packages\django\template\base.py", line 910, in render_annotated
return self.render(context)
File "C:\Users\gokul\Desktop\TESTING\data\lib\site-packages\django\template\loader_tags.py", line 155, in render
return compiled_parent._render(context)
File "C:\Users\gokul\Desktop\TESTING\data\lib\site-packages\django\template\base.py", line 167, in _render
return self.nodelist.render(context)
File "C:\Users\gokul\Desktop\TESTING\data\lib\site-packages\django\template\base.py", line 943, in render
bit = node.render_annotated(context)
File "C:\Users\gokul\Desktop\TESTING\data\lib\site-packages\django\template\base.py", line 910, in render_annotated
return self.render(context)
File "C:\Users\gokul\Desktop\TESTING\data\lib\site-packages\django\template\loader_tags.py", line 67, in render
result = block.nodelist.render(context)
File "C:\Users\gokul\Desktop\TESTING\data\lib\site-packages\django\template\base.py", line 943, in render
bit = node.render_annotated(context)
File "C:\Users\gokul\Desktop\TESTING\data\lib\site-packages\django\template\base.py", line 910, in render_annotated
return self.render(context)
File "C:\Users\gokul\Desktop\TESTING\data\lib\site-packages\django\template\defaulttags.py", line 447, in render
url = reverse(view_name, args=args, kwargs=kwargs, current_app=current_app)
File "C:\Users\gokul\Desktop\TESTING\data\lib\site-packages\django\urls\base.py", line 88, in reverse
return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
File "C:\Users\gokul\Desktop\TESTING\data\lib\site-packages\django\urls\resolvers.py", line 632, in _reverse_with_prefix
raise NoReverseMatch(msg)
django.urls.exceptions.NoReverseMatch: Reverse for 'django.contrib.auth.views.login' not found. 'django.contrib.auth.views.login' is not a valid view function or pattern name.
[17/Jan/2018 17:22:04] "GET /login/?next=/ HTTP/1.1" 500 153293
I have a login.html
template with contains the following:
<form method="post" action="{% url 'django.contrib.auth.views.login' %}">
If I change the url tag as follows, then I am getting another traceback.
<form method="post" action="{% url django.contrib.auth.views.login %}">
Django version 2.0.1, using settings 'tagent.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Internal Server Error: /login/
Traceback (most recent call last):
File "C:\Users\gokul\Desktop\TESTING\data\lib\site-packages\django\core\handlers\exception.py", line 35, in inner
response = get_response(request)
File "C:\Users\gokul\Desktop\TESTING\data\lib\site-packages\django\core\handlers\base.py", line 158, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\gokul\Desktop\TESTING\data\lib\site-packages\django\core\handlers\base.py", line 156, in _get_response
response = response.render()
File "C:\Users\gokul\Desktop\TESTING\data\lib\site-packages\django\template\response.py", line 106, in render
self.content = self.rendered_content
File "C:\Users\gokul\Desktop\TESTING\data\lib\site-packages\django\template\response.py", line 83, in rendered_content
content = template.render(context, self._request)
File "C:\Users\gokul\Desktop\TESTING\data\lib\site-packages\django\template\backends\django.py", line 61, in render
return self.template.render(context)
File "C:\Users\gokul\Desktop\TESTING\data\lib\site-packages\django\template\base.py", line 175, in render
return self._render(context)
File "C:\Users\gokul\Desktop\TESTING\data\lib\site-packages\django\template\base.py", line 167, in _render
return self.nodelist.render(context)
File "C:\Users\gokul\Desktop\TESTING\data\lib\site-packages\django\template\base.py", line 943, in render
bit = node.render_annotated(context)
File "C:\Users\gokul\Desktop\TESTING\data\lib\site-packages\django\template\base.py", line 910, in render_annotated
return self.render(context)
File "C:\Users\gokul\Desktop\TESTING\data\lib\site-packages\django\template\loader_tags.py", line 155, in render
return compiled_parent._render(context)
File "C:\Users\gokul\Desktop\TESTING\data\lib\site-packages\django\template\base.py", line 167, in _render
return self.nodelist.render(context)
File "C:\Users\gokul\Desktop\TESTING\data\lib\site-packages\django\template\base.py", line 943, in render
bit = node.render_annotated(context)
File "C:\Users\gokul\Desktop\TESTING\data\lib\site-packages\django\template\base.py", line 910, in render_annotated
return self.render(context)
File "C:\Users\gokul\Desktop\TESTING\data\lib\site-packages\django\template\loader_tags.py", line 67, in render
result = block.nodelist.render(context)
File "C:\Users\gokul\Desktop\TESTING\data\lib\site-packages\django\template\base.py", line 943, in render
bit = node.render_annotated(context)
File "C:\Users\gokul\Desktop\TESTING\data\lib\site-packages\django\template\base.py", line 910, in render_annotated
return self.render(context)
File "C:\Users\gokul\Desktop\TESTING\data\lib\site-packages\django\template\defaulttags.py", line 447, in render
url = reverse(view_name, args=args, kwargs=kwargs, current_app=current_app)
File "C:\Users\gokul\Desktop\TESTING\data\lib\site-packages\django\urls\base.py", line 88, in reverse
return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
File "C:\Users\gokul\Desktop\TESTING\data\lib\site-packages\django\urls\resolvers.py", line 632, in _reverse_with_prefix
raise NoReverseMatch(msg)
django.urls.exceptions.NoReverseMatch: Reverse for '' not found. '' is not a valid view function or pattern name.
[17/Jan/2018 17:37:56] "GET /login/?next=/ HTTP/1.1" 500 152780
Could someone give me a pointer on what went wrong?
You should use the URL pattern name, not the dotted python path.
You haven't shown how you are including the login view in your URLs, so we can only guess what the correct name is, but it's probably 'login'
.
<form method="post" action="{% url 'login' %}">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With