Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Having issues with passing vars to html files using flask

I am trying to make a card game in python for the web and i need to generate random cards, when i do this i run a function that makes the file name of the card.

def create_card_name():
    random = get_random_line("random.txt")
    alsorandom = get_random_line("alsorandom.txt")
    ## return alsorandom + random + ".svg"
    print(alsorandom +"_"+ random)

Then i create it when the site is opened i get the values set to vars:

    card1 = create_card_name()
    card2 = create_card_name()
    card3 = create_card_name()
    card4 = create_card_name()

When i pass it in with:
return render_template('card-game.html',card1=card1,card2=card2,card3=card3,card4=card4)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I get none for some reason. See this image

Anyone know why this is not working?

>Solution :

inside create_card_name function, you should return a value. and return statement must be last line. your last line is print(..) which returns None thus your create_card_name() evaluates to None

def create_card_name():
    random = get_random_line("random.txt")
    alsorandom = get_random_line("alsorandom.txt")
    print(alsorandom +"_"+ random)
    return alsorandom + random + ".svg"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading