JSchrantz
JSchrantz

Reputation: 45

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 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.

Upvotes: 3

Views: 963

Answers (1)

systempuntoout
systempuntoout

Reputation: 74164

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

Upvotes: 3

Related Questions