#NoReverseMatch at /createannouncement/

1 messages · Page 1 of 1 (latest)

crisp trout
#

Reverse for 'createannouncement/' not found. 'createannouncement/' is not a valid view function or pattern name.

#

@south bluff can you help please

analog kettle
crisp trout
#

ok

analog kettle
#

So do other users, and they do just fine asking a question and patiently waiting for a response.

crisp trout
#

ok

wheat crystal
crisp trout
#

i got it

crisp trout
wheat crystal
#

Make it work

crisp trout
#

im new

#

i tried

wheat crystal
#

You gave zero information, what you expect from us? If you say it doesn't work I say make it work. If you say you tried I say try again. If you share code and error traceback - then maybe we'll have something to work with

crisp trout
#

base.html

              <a class="nav-link" href="{% url 'logout' %}">LogOut</a>
            </li>

urls.py

 path("logged_out/", LogoutView.as_view(next_page="/login/"), name="logout"),

logged_out.html

{% block title %}Logged Out{% endblock %}

{% block content %}
<h1>Logged Out</h1>
<p>
    You have been successfully logged out.
    you can <a href="{% url 'login' %}">log-in again</a>.
</p>
{% endblock %}
wheat crystal
#

Ok, templates look ok, what is the error?

crisp trout
#

http://127.0.0.1:8000/logged_out/

wheat crystal
#

405 method not allowed (what the hell is "page isn't working"? Lol)

#

You are trying to logout with GET method most likely, that is not allowed

crisp trout
#

then?

wheat crystal
#

You need to make a POST request, usually by making logout button a <form> submit

crisp trout
#

oh

wheat crystal
#
  <li class="nav-item">
              <a class="nav-link" href="{% url 'logout' %}">LogOut</a>
    </li>

instead of this

#

or make a form on logout page itself, but it's more work

#

You can just use an inline form and styleze button as a link

crisp trout
#

thanks

#

it worked thanks

south bluff
#

you can make your code much more readable here on discord via

```py

code here

```

#

or for django templates use

```django

template here

```

crisp trout
#

thanks

crisp trout
#

<form action='{% url "logout"%}' method="POST">

crisp trout
wheat crystal
#

Ah, wait

#

So which of the errors? That's different matters

crisp trout
# wheat crystal Show your urls please
from . import views
from django.urls import path
from django.conf import settings
from django.conf.urls.static import static
from .views import contact_view, contact_success_view, login_view, register_view
from django.contrib.auth import logout


urlpatterns = [
    path("", views.AllPostsView.as_view(), name="home"),
    path("create_post/", views.create_post, name="create_post"),
    path("login/", login_view, name="login"),
    path("logout/", logout, name="logout"),
    path("register/", register_view, name="register"),
    path("<slug:slug>/", views.DjangoDetail.as_view(), name="django_detail"),
]
crisp trout
wheat crystal
#

It shouldn't give this error

crisp trout
#

how to fix

crisp trout
#
<form action="{% url 'logout' %}" method="POST">
                  {% csrf_token %}
                  <input
                    type="submit"
                    value="Logout"
                    class="my-style-for-logout-button"
                  />
                </form>
wheat crystal
#

Not sure for now, you didn't touch Django code?

crisp trout
#

ok

wheat crystal
#

Problem is in the view

#

What is the full traceback of the error?

crisp trout
# wheat crystal What is the full traceback of the error?
Environment:


Request Method: POST
Request URL: http://127.0.0.1:8000/logout/

Django Version: 5.0.1
Python Version: 3.12.2
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'Blog_app']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback (most recent call last):
  File "C:\Users\mvams\krish\Lib\site-packages\django\core\handlers\exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\mvams\krish\Lib\site-packages\django\core\handlers\base.py", line 204, in _get_response
    self.check_response(response, callback)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\mvams\krish\Lib\site-packages\django\core\handlers\base.py", line 332, in check_response
    raise ValueError(
    ^

Exception Type: ValueError at /logout/
Exception Value: The view django.contrib.auth.logout didn't return an HttpResponse object. It returned None instead.