开发者

Google App Engine get and post on the same model

I am new to google app engine/webapp and trying to get a simple app running. The app will be for a demo car rental service. I would like to have开发者_JAVA技巧 a request handler for adding new cars that handles both a get and a post for the add car page.

The get should return a form to be filled and submitted. The post should add the car (I am not worried about this yet) and then return a similar page with a form and 'car successfully added' or something similar.

Here was my approach:

URL Mapping:

application = webapp.WSGIApplication([('/employee/add/car', AddCar)],
                                      debug=True)

AddCar:

class AddCar(webapp.RequestHandler):
    def get(self):
        self.response.out.write(template.render('templates/addcar.html', {}))

    def post(self):
        self.response.out.write(template.render('templates/addcarsuccess.html', {}))

addcar.html Template:

{% extends "base.html" %}

{% block body %}
    <h2>Add a Car</h2>

    <form action="/employee/add/car" method="post">
        <label>Make</label>
        <input type="text" name="make"></input>
        <br/>
        <input type="submit"></input>
    </form>
{% endblock body %}

I get a 405 Method Not Allowed response when I submit the form shown above.

I tried doing prints, raising exceptions, etc in the post function just to see if it is being called and it doesn't look like it is.

I tried pulling the post out into a separate class and that seemed to work, but I would rather have them in the same handler.

I hope that I am missing something simple that will let me accomplish this.

Any Ideas?

Thanks.


I've tested your code and is correct, my guess is that the original post method in your code has some indentation error.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜