'Django form doesn't send POST request and site freezes
I'm trying to set up a basic forum site for my coworkers to use. The problem is that when I attempt to log in to the site, no POST request is sent (shown by the terminal) and the entire website becomes unresponsive. In fact, it's sitting in another browser tab buffering infinitely as I type this.
I followed Corey Schafer's Django tutorials to lay the groundwork of the site, as I've never done anything with Django. I finished the tutorial series, and the site was fully functioning (minus the password-reset emails). After finishing the tutorials, I added a tagging feature to the post-form through django-taggit.
I had to wait until the head of IT could input some files into the company site to access emails (through SendGrid), but I finally was able to send a single password-reset email to myself. I successfully reset my password, and this is where things started to go wrong.
I wanted to change my password back, so I went through the process again, but this time when I pressed the "Send Email" button on the password-reset page, the buffering icon (on Chrome), started going backwards and wouldn't stop. I didn't check my console when this happened. Either way, I attempted to go to somewhere else on the site by clicking links on the navigation bar, but all the links were unresponsive. All that refreshing did was clear the form.
Now, every time I attempt to send a POST request, this happens, and the entire site is unusable. I cannot log in, post, change my password, or create accounts.
I've tried to fix this by clearing my browser's cache, flushing the database, and inspecting the console to see if I was getting errors. The console doesn't show any errors. In fact, it only shows the last GET request that was sent. In the case of logging in, the last request says:
[19/Aug/2019] "GET /login/ HTTP/1.1" 200 5214
Note that I had attempted to begin learning SQL at around this time, and I have MySQL installed on the same computer. Could it have something to do with an occupied port? I'm working on localhost:8000, if that's any help.
I need to figure out why POST requests aren't being sent, but I don't know what is causing this issue as there are no errors or exceptions.
EDIT *forgot to add:
I have also tried restarting the server and checking for migrations, but neither of those actions had any effect as well. I also attempted to create a new user, and again it failed.
I also opened a pre-existing and functioning version of the code, but even that is failing, so this may be a hardware issue.
EDIT #2:
Here is the HTML for the Login page, I'm extending a basic HTML template that doesn't affect the login form, and I'm also using Crispy Forms as directed by Corey Schafer's tutorial. Here's the HTML:
<div class='content-section'>
<form method="POST">
{% csrf_token %}
<fieldset class="form-group">
<legend class="border-bottom mb-4">
Team Member Login
</legend>
{{ form|crispy }}
</fieldset>
<div class="form-group">
<button class="btn btn-outline-info" type="submit">Log In</button>
<small class="text-muted ml-2">
<a href="{% url 'password_reset' %}">Forgot Password?</a>
</small>
</div>
</form>
</div>
EDIT #3:
This is how the view is configured...
path('login/',
auth_views.LoginView.as_view(template_name='users/login.html'),
name='login')
EDIT #4:
I was able to successfully register a new user, and I was even able to log them in from the login page, but after a second attempt in which I logged them out and tried to log back in, the problem appeared again. I have a single POST request from my console. Here's the console output:
System check identified no issues (0 silenced).
August 19, 2019 - 15:57:16
Django version 2.2.4, using settings 'django_project.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
[19/Aug/2019 15:57:24] "GET / HTTP/1.1" 200 3890
Not Found: /favicon.ico
[19/Aug/2019 15:57:26] "GET /favicon.ico HTTP/1.1" 404 5049
[19/Aug/2019 15:57:30] "GET /register/ HTTP/1.1" 200 6525
[19/Aug/2019 15:57:47] "POST /register/ HTTP/1.1" 302 0
[19/Aug/2019 15:57:47] "GET /login/ HTTP/1.1" 200 5389
[19/Aug/2019 15:57:54] "POST /login/ HTTP/1.1" 302 0
[19/Aug/2019 15:57:54] "GET / HTTP/1.1" 200 3979
[19/Aug/2019 15:57:59] "GET /profile/ HTTP/1.1" 200 5288
[19/Aug/2019 15:58:04] "GET /logout/ HTTP/1.1" 200 4055
Solution 1:[1]
Your form doesn't specify an action. So, I am assuming, on submit form, the current page is being loaded to handle the form submission.
If you are using a method based view
def viewHandle(request):
if request.method == "POST":
return something
If you are using a class based view
class HomePage(View):
def post(self, request):
return something
def get(self, request):
return something
Solution 2:[2]
Happened in Google Chrome but works in Safari. So, I checked if I have a pending Chrome update. Afterward, it worked like a charm.
Solution 3:[3]
Well. I had a similar problem where Django would hang on any POST request I did and subsequent GET requests. Especially on the login page and admin. The browser would just say either ERR_CONNECTION_REFUSED
or ERR_EMPTY_RESPONSE
. It turns out I had enabled caching with redis
on my Django app and it the redis-server
wasn't on. After starting it, everything worked perfectly.
Solution 4:[4]
It happened to me also but while resetting password for users I tried everything
1-Checking the action and the method
2-Restarting the project
3-Clearing cache
but eventually it was the browser that needed to be updated
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | dotslash227 |
Solution 2 | Rodimus Altarian |
Solution 3 | iMitwe |
Solution 4 | Mahmoud Mohammed Aboelella |