Lightster
Lightster

Reputation: 119

error 405 web.py

I got an error 405 as you can read, here is my code and my guess of what's wrong. The code is pretty basic, they are 3 files, main.py, blog.py, and form.html. As additional info: this code uses sessions, a subapp, and templates.

main.py --

import web
import blog

urls = (
  "/blog", blog.app_blog,
  "/(.*)", "index"
)

web.config.debug = False
app = web.application(urls, locals())
session = web.session.Session(app, web.session.DiskStore('sessions'))    
render = web.template.render('views/', globals = {'session': session})

class index:

    def GET(self, path):
        session.names = ''
        session.surnames = ''
        session.nin = ''
        session.address = ''
        session.phone = ''
        session.email = ''
        return render.form()


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

--

blog.py --

import web
urls = (
  "", "reblog",
  "/", "blog"
)

class reblog:
    def GET(self): raise web.seeother('/')

class blog:
    def GET(self):
        return "getblog"
    def POST(self):
        return "postblog"

app_blog = web.application(urls, locals())

-- form.html--

<form method=post action=blog>
    <ul>
        <li><input name=names required maxlength=24 placeholder="Name" value="$session.names"></li>
        <li><input name=surnames required maxlength=24 placeholder="Surname" value="$session.surnames"></li>
        <li><input name=nin requiered maxlength=12 placeholder="RUT" value="$session.nin"></li>
        <li><input name=address required maxlenght=64 placeholder="Address" value="$session.address"></li>
        <li><input name=phone required maxlength=10 placeholder="Phone" value=$session.phone></li>
        <li><input name=email type=email required maxlenght=254 placeholder="email" value=$session.email></li>
        <li><input name=password type=password required placeholder="password"></li>
        <li><input name=confirmpassword type=password required placeholder="Confirmar pass"></li>
        <li><input type=submit value="registrarse"></li>
    </ul>

The thing is that the user inputs are not use by the POST, rather it gives me an error 405 exactly like this: "HTTP/1.1 POST /blog" - 405 Method Not Allowed

and the browser prints None.

Please give me a hand guys, this is pretty frustrating, if you know what I mean.

Thanks beforehand.

Cheers.

Upvotes: 1

Views: 1700

Answers (1)

Andrey Kuzmin
Andrey Kuzmin

Reputation: 4479

It happens because /blog url is mapped to class reblog that doesn't have POST method defined.

Upvotes: 1

Related Questions