0

This basic form is working as expected in python. It displays the contents of user submitted data to browser. What I need to do is pass this text string to pika to be sent to rabbitmq.

templates/hello_form1.html

<html>
<body>

<h1>Submit the Form</h1>

<form action="/hello" method="POST">
    file to download: <input type="text" name="greet">
    <br/>
    <input type="submit">
</form>

</body>
</html>

templates/index.html

$def with (greeting)

$if greeting:
    I just wanted to say <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 I add this 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)

1 Answer 1

1

I'd suggest to put it 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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.