2

I am new to python web applications. I am using Bottlepy for my web application and request for extracting variables from URLs. I extracted the variable first=request.query.first. I can return the value of the variable but when I want to use it in if condition it always fails and else block is executed.

URL: http://127.0.0.1:8080/h?first="hi"

@app.route('/h')
def test():
    first=request.query.first
    if first == "hi":
        return "passed"
    else:
        return "fail"

I will appreciate your help regarding the problem thank you.

2
  • Hint: Before your if statement, simply print out the value of first. Commented Jul 21, 2017 at 23:14
  • Before if statement the print result is "hi" but still the if condition fails. Commented Jul 22, 2017 at 8:37

2 Answers 2

2

I tested the URL many times then I noticed that I was putting quotation marks around "hi" removing the quotation fixed the problem. The new URL is http://localhost:8080/h?first=hi.

Sign up to request clarification or add additional context in comments.

Comments

0

this should effectively convert the URL variable to string. after you do first=request.query.first

newfirst=str(first)

then in the test function change first to newfirst

def test():
    if newfirst == "hi":
        return "passed"
    else:
        return "fail"

1 Comment

Thanks for the reply but it still fails.

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.