Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialigsm '
10,440 PointsWhat does ...methods['POST']) mean?
Kenneth Love : 'I want this to only be accessible, if you post to it...'?
@app.route('/save', methods=['POST'])
What does this mean and where does methods=['POST'] come from?
3 Answers
Andreas cormack
Python Web Development Techdegree Graduate 33,011 Pointshere is a link that might help with GET and POST http://www.cs.tut.fi/~jkorpela/forms/methods.html
Andreas cormack
Python Web Development Techdegree Graduate 33,011 PointsHi igors
there are two http methods GET and POST. I think of it as GET being getting something from the url to be used in the view and POST posting values to the view. So if a user visits yourdomain/save/2 your getting the value 2 from the url which could be an ID of some sort and is GET request. POST is normally values coming from a form. In flask if your posting values from a form for example your route should look like this or you will get the error 'not allowed'.
@app.route('/save',methods=['GET','POST'])
def save():
#if you want to execute code only when the request is post you can do this
if request.method=='POST':
#do something.
If you are using WT forms then it is quite smart and you wont need the request.method line.
igsm '
10,440 PointsOk. I kind of understood the POST bit. Still struggle to understand GET. I tested it in two ways, using GET and POST. So when I have only POST as a method, I get a new view (what function returns) if I submit a value through the form. For example, if we take a case from the video tutorial; I get to the next view (route) 'Saved!' if I submit a value in the form (this is with having POST as a method). If I have GET as a method, my submission through the form does not work, it works only if I add a route manually into URL.
Not sure if that makes sense but why do we need GET method and when should we use it?
igsm '
10,440 Pointsigsm '
10,440 PointsThanks. This's helpful.