Question

I am new to webpy and python, I just tested the basic GET and POST on my laptop.

Here is the code:

import web

urls = (
    "/get", "get",
    "/post", "post"
)
app = web.application(urls, globals())

class test:
    def GET(self):
        return "get"

class post:
    def POST(self):
        return "post"

if __name__ == "__main__":
    app.run()  

The GET works OK, but POST returns 405 Method Not Allowed error.

Anyone could give me a hand? Thanks.

Was it helpful?

Solution

When you check if POST is working are you actually sending/posting any data to the server? If you navigate to the url "/post" you will make a "GET" request to the server and since there is no GET function for that url it will return "405 Method Not Allowed".

So if you would like to make something like a form, you would have a GET function that returned the page to the user, and then a POST function to receive the input from the form and do something with it on the server. Both within the same url class.

Hope that helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top