This method is not allowed for the requested URL

**Question:when i login then there is error or says this method is not allowed for the requested URL

**Current behavior:*hen i login then there is error or says this method is not allowed for the requested URL

Desired behavior

**Repl link:**s://

code snippet
1 Like

hi! I tested your app, and using the devTools it seems like the request is being done via a GET request

(see the cursor).
I think this is because in your login.html file, you have the attribute misspelled. It should be method="post", not methods="post".
Hope this helps!

1 Like

I write the methods=“POST” .So this is not the problem.

Exactly. You have to take the S out. It’s method=“POST”, not methods=“POST”.

I use the method=“POST” .
But they are saying now there is some internal error

Hi, i got it working!
The problem was that you did not have any key named “user” in the database. So you were getting a KeyError.

In the start of after import statements, put this code:

db["user"] = {
  "username": "abc",
  "password": "abc"

Run it once, stop the program and then remove these lines.
This creates a user with username abc and password abc.
I said to remove them as once you have the key existing, you don’t need to do it again. It might cause some problems later.

Also in login.html, close the input tags:

<p> Username: <input type ="text" name="username" required></p>
<p> Password: <input type ="password" name="password" required></p>

Done! Problem solved!

Now i will also show how to identify this and fix this yourself:

  1. Once you get an error, look at the console. Here is the error:

  2. Usually, the the last few lines only matters. The last lines say us that there was a KeyError and also showed us the line. It says that the key “users” doesnt exist. So make the key.

I saw you reading a HTML file and returning the code as a string. Instead of that, use this:
import the function

from flask import render_template

use it

def page():
    return render_template("login.html") #actual path templates/login.html is not specified since templates folder is checked by default

And put login.html in the template folder: templates/login.html

1 Like

I try it .But there is 302 or 404 code error

A quick google search says that 302 means the resource requested has been temporarily moved. Which means that something is redirecting that request for some reason.

I tested the code and answered. Check for yourself: - site - code

This is very useful topic for me.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.