0

I was trying to put a link in some text through url_for (flask, python3) and also pass a variable but nothing I tried worked .Here's the code I used. Am I doing something wrong? html5:

<a class="mr-2" href={{ url_for('user','username'=posts.author)}} >TEXT</a>

python3:

@app.route('/user')
def user(username):
    print(username)

1 Answer 1

1

You'd need to change the template code to look like:

<a class="mr-2" href="{{ url_for('user',username=posts.author) }}" >TEXT</a>

However you'd also have to change the python code for this to be valid:

@app.route('/user/<username>')
def user(username):
    print(username)

A valid request is now:

/user/CodEdo

Which is the URL which should be rendered in the href assuming that posts.author in the template is CodEdo.

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.