Home > Net >  Having issues with passing vars to html files using flask
Having issues with passing vars to html files using flask

Time:11-29

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)

I get none for some reason. See this image

Anyone know why this is not working?

CodePudding user response:

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"
  • Related