processing form inputs in python -
this basic form working expected in python. displays contents of user submitted data browser. need pass text string pika sent rabbitmq.
templates/hello_form1.html
<html> <body> <h1>submit form</h1> <form action="/hello" method="post"> file download: <input type="text" name="greet"> <br/> <input type="submit"> </form> </body> </html>
templates/index.html
$def (greeting) $if greeting: wanted <em style="color: green; font-size: 2em;">$greeting</em>. $else: <em>hello</em>, world!
cat app2.py
import web urls = ( '/hello', 'index' ) app = web.application(urls, globals()) render = web.template.render('templates/') class index(object): def get(self): return render.hello_form1() def post(self): form = web.input(name="nobody", greet="hello") greeting = "%s, %s" % (form.greet, form.name) return render.index(greeting = greeting) if __name__ == "__main__": app.run()
where should add block of text?
import pika connection = pika.blockingconnection(pika.connectionparameters(host='localhost')) channel = connection.channel() channel.queue_declare(queue='mylog') channel.basic_publish(exchange='', routing_key='mylog', body=$greeting)
i'd suggest put in def post(self)
:
class index(object): ... def post(self): form = web.input(name="nobody", greet="hello") greeting = "%s, %s" % (form.greet, form.name) connection = pika.blockingconnection(pika.connectionparameters(host='localhost')) channel = connection.channel() channel.queue_declare(queue='mylog') channel.basic_publish(exchange='', routing_key='mylog', body=greeting) return render.index(greeting = greeting)
Comments
Post a Comment