I keep getting a 405 error on my Django Blog

I'm having an issue with my Django Blog. Every time I try to turn on the About Me Page, I get a 405 Error.

For context, here's my code:

posts/views.py:

from django.views.generic import View
from .models import Post



class AboutView(View):
    template_name = "aboutme.html"

posts/url.py:


from django.urls import re_path
from .views import AboutView
urlpatterns = [
re_path(r'post/aboutme/', AboutView.as_view())

]

templates/base.html:

<body>
 <div class="container">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
                    <div class="container-fluid">
                      <a class="navbar-brand" href="#">Navbar</a>
                      <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
                        <span class="navbar-toggler-icon"></span>
                      </button>
                      <div class="py-2 bg-body-tertiary border-bottom">
                        <div class="py-2 bg-body-tertiary border-bottom">
                          <ul class="nav me-auto">
                                                        <li class="nav-item"><a class="nav-link" href="">Homepage</a></li>
                            <li class="nav-item"><a class="nav-link" href="/posts">Blog</a></li>
                            <li class="nav-item"><a class="nav-link" href="/post/aboutme/">About Me</a></li>
                            <li class="nav-item"><a class="nav-link" href="#">Portfolio</a></li>
</ul>
 </div>
                      </div>
                    </div>
                </nav>
            </div>
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
        <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>

For the sake of clarity, I've included the About Me page:

{% extends 'base.html' %}
{% block title %} 
About Me 
{% endblock %}

{% block content %} 
<div class="center">
<p>
    Salutations!
    I'm TheBigL. A software Developer by trade.
</p> 
</div>

{% endblock %}

I always seem to get a 405 every time I open the About Me page. Is there any way I can fix this issue? Is my view configured correctly? Please let me know. Thanks in advance.

I search in Google. I've even tried to do method-based answers, but I wasn't satified with the result. I've even looked up folks who had similar issues, but it's nothing like what I have at the moment. It's relatively simple. Mine is a GET request, rather than a POST request.

EDIT: I forgot to change the import to this current state. It's something that I forgot.

You are not correctly importing Django's View in from django.views.generic. It should be:

from django.views import View

See Using class-based views.

Вернуться на верх