I can resolve this issue via this way, but use the button is so ugly in my web application.
This is not the rendered html of your template. Your template is showing a button tag, your html is showing an anchor (<a>
) tag. Either you made a mistake including/loading the correct template in one of your views or you’re showing the html output of a view which is not related to your template shown above.
You can use CSS to style a button like a link.
Hi, my logout page is not working. Can anyone help?
In views:
class PatchLogoutView(LogoutView):
http_method_names = [“get”, “post”, “options”]
def get(self, request, *args, **kwargs):
return self.post(request, *args, **kwargs)
In URL:
rom django.contrib import admin
from django.urls import path,include
from .views import Index,SignUpView,PatchLogoutView
from django.contrib.auth import views as auth_views
from rest_framework import routers, serializers, viewsets
urlpatterns = [
path(‘’,Index.as_view(),name=‘index’),
path(‘signup/’,SignUpView.as_view(),name=‘signup’),
path(‘login/’,
auth_views.LoginView.as_view(template_name=‘inventory/login.html’),name=‘login’),
path(“api-auth/logout/”, PatchLogoutView.as_view(), name=‘logout’),
path(‘api-auth/’, include(‘rest_framework.urls’,namespace=“rest_framework”)),
]
I tried something like this on the navbar itself on basic.html, it seems to have worked. Just adding, if it helps for some idea.
<div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="navbar-nav cssnavls">
<li class="nav-item">
<a class="nav-link" href="#">Groups</a>
</li>
{% if user.is_authenticated %}
<li class="nav-item">
<a class="nav-link" href="#">Create Group</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Post</a>
</li>
<li class="nav-item">
{% block Logoutblock %}
{% if user.is_authenticated %}
<form method="post" action="{% url 'logout' %}">
{% csrf_token %}
<button class=" btn btn-primary " type="submit">Log Out</button>
</form>
{% else %}
<form method="get" action="{% url 'useraccountslogin' %}">
{% csrf_token %}
<button class=" btn btn-primary " type="submit">Log In</button>
</form>
{% endif %}
{% endblock %}
</li>
{% else %}
<li class="nav-item">
<a class="nav-link" href="{% url 'useraccountslogin' %}">LogIn</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'useraccountssignup' %}">SignUp</a>
</li>
{% endif %}
</ul>