def post(): '''New post submission.''' message = request.form['content'] print((message, )) print('ENDERECO PARA A MAIN') print(url_for('main')) add_post(message) return redirect(url_for('main'))
def post(env, resp): """Post handles a submission of the forum's form. The message the user posted is saved in the database, then it sends a 302 Redirect back to the main page so the user can see their new post. """ # Get post content input = env["wsgi.input"] length = int(env.get("CONTENT_LENGTH", 0)) # If length is zero, post is empty - don't save it. if length > 0: postdata = input.read(length) fields = cgi.parse_qs(postdata) content = fields["content"][0] # If the post is just whitespace, don't save it. content = content.strip() if content: # Save it in the database forumdb.add_post(content) # 302 redirect back to the main page headers = [("Location", "/"), ("Content-type", "text/plain")] resp("302 REDIRECT", headers) return ["Redirecting"]
def Post(env, resp): """Post handles a submission of the forum's form. The message the user posted is saved in the database, then it sends a 302 Redirect back to the main page so the user can see their new post. """ # Get post content wsgi_input = env['wsgi.input'] length = int(env.get('CONTENT_LENGTH', 0)) # If length is zero, post is empty - don't save it. if length > 0: postdata = wsgi_input.read(length) fields = cgi.parse_qs(postdata) content = fields['content'][0] # If the post is just whitespace, don't save it. content = content.strip() if content: # Save it in the database forumdb.add_post(content) # 302 redirect back to the main page headers = [('Location', '/'), ('Content-type', 'text/plain')] resp('302 REDIRECT', headers) return ['Redirecting']
def post(env, resp): # Post handles a submission of the forum's form. # The message the user posted is saved in the database, then it sends a 302 # Redirect back to the main page so the user can see their new post. # Get post content input = env['wsgi.input'] length = int(env.get('CONTENT_LENGTH', 0)) # If length is zero, post is empty - don't save it. if length > 0: postdata = input.read(length) fields = urlparse.parse_qs(postdata) content = fields['content'][0] # If the post is just whitespace, don't save it. content = content.strip() if content: # Save it in the database forumdb.add_post(content) # 302 redirect back to the main page headers = [('Location', '/'), ('Content-type', 'text/plain')] resp('302 REDIRECT', headers) return ['Redirecting']
def post(): '''New post submission.''' message = request.form['content'] add_post(message) return redirect(url_for('main'))
def post(): '''New post submission.''' message = request.form['content'] better_message = bleach.clean(message) add_post(better_message) return redirect(url_for('main'))