Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

django.urls.exceptions.NoReverseMatch: Reverse for 'oidc_logout' not found. 'oidc_logout' is not a valid view function or pattern name. #531

Open
Alwinator opened this issue Mar 14, 2024 · 1 comment

Comments

@Alwinator
Copy link

Alwinator commented Mar 14, 2024

I am using mozilla-django-oidc version 4.0.1 and Django 5.0.3. I get the error when I request the view from the browser. Without the oidc_logout form it works fine. I think it is really strange that oidc_authentication_init works, but oidc_logout does not.

[14/Mar/2024 07:13:46] "GET /accounts/login/ HTTP/1.1" 500 151875
Internal Server Error: /accounts/login/
Traceback (most recent call last):
  File "/Users/MyUser/Programming/TestDjangoOAuth2/.venv/lib/python3.12/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/MyUser/Programming/TestDjangoOAuth2/.venv/lib/python3.12/site-packages/django/core/handlers/base.py", line 220, in _get_response
    response = response.render()
               ^^^^^^^^^^^^^^^^^
  File "/Users/MyUser/Programming/TestDjangoOAuth2/.venv/lib/python3.12/site-packages/django/template/response.py", line 114, in render
    self.content = self.rendered_content
                   ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/MyUser/Programming/TestDjangoOAuth2/.venv/lib/python3.12/site-packages/django/template/response.py", line 92, in rendered_content
    return template.render(context, self._request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/MyUser/Programming/TestDjangoOAuth2/.venv/lib/python3.12/site-packages/django/template/backends/django.py", line 61, in render
    return self.template.render(context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/MyUser/Programming/TestDjangoOAuth2/.venv/lib/python3.12/site-packages/django/template/base.py", line 171, in render
    return self._render(context)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/MyUser/Programming/TestDjangoOAuth2/.venv/lib/python3.12/site-packages/django/template/base.py", line 163, in _render
    return self.nodelist.render(context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/MyUser/Programming/TestDjangoOAuth2/.venv/lib/python3.12/site-packages/django/template/base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/MyUser/Programming/TestDjangoOAuth2/.venv/lib/python3.12/site-packages/django/template/base.py", line 961, in render_annotated
    return self.render(context)
           ^^^^^^^^^^^^^^^^^^^^
  File "/Users/MyUser/Programming/TestDjangoOAuth2/.venv/lib/python3.12/site-packages/django/template/defaulttags.py", line 326, in render
    return nodelist.render(context)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/MyUser/Programming/TestDjangoOAuth2/.venv/lib/python3.12/site-packages/django/template/base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/MyUser/Programming/TestDjangoOAuth2/.venv/lib/python3.12/site-packages/django/template/base.py", line 961, in render_annotated
    return self.render(context)
           ^^^^^^^^^^^^^^^^^^^^
  File "/Users/MyUser/Programming/TestDjangoOAuth2/.venv/lib/python3.12/site-packages/django/template/defaulttags.py", line 479, in render
    url = reverse(view_name, args=args, kwargs=kwargs, current_app=current_app)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/MyUser/Programming/TestDjangoOAuth2/.venv/lib/python3.12/site-packages/django/urls/base.py", line 88, in reverse
    return resolver._reverse_with_prefix(view, prefix, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/MyUser/Programming/TestDjangoOAuth2/.venv/lib/python3.12/site-packages/django/urls/resolvers.py", line 851, in _reverse_with_prefix
    raise NoReverseMatch(msg)
django.urls.exceptions.NoReverseMatch: Reverse for 'oidc_logout' not found. 'oidc_logout' is not a valid view function or pattern name

This error message is caused by the following view:

{% if user.is_authenticated %}
  <p>Current user: {{ user.email }}</p>
  <form action="{% url 'oidc_logout' %}" method="post">
    {% csrf_token %}
    <input type="submit" value="logout">
  </form>
{% else %}
  <a href="{% url 'oidc_authentication_init' %}">Login</a>
{% endif %}
@Alwinator
Copy link
Author

Alwinator commented Mar 14, 2024

Fixed it by adding

urlpatterns = [
    ...
    path("logout/", OIDCLogoutView.as_view(), name="oidc_logout")
]

to my urls.py, however I think that should also work without because I have also added

path('oidc/', include('mozilla_django_oidc.urls')),

before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant