Website game using python html django or flask

how would I be able to attach my python game to my website using python and hml and django flask if nesscery

Hi @DEV-MEASTRO, welcome!

Are you using Django or Flask?

1 Like

@QwertyQwerty88 Flask as it’s more easier for me

When you use Flask, Python is your back-end. Games and text should be written in HTML.
It’s possible to do what you want, but could you elaborate further on the game that you want to include?

@NateDhaliwalit’s just a simple game i made using pygame nothing special but i just want to attach it to a website i made instead of looking on replit

@NateDhaliwal mainly a simple block game

@NateDhaliwal could you ellaborate on what you mean by back end for me

Backend is like Node.js when creating websites, and like Python, it manages the app routes etc.
HTML is a frontend because that is what the user sees. The 2 connect to form a full webserver.

How many files does your game have?

To be honest, I’m not sure how you would do this with Flask. Correct me if I’m wrong, as I haven’t learned Flask yet, but I believe you would have to use something like Pyscript to attach your Pygame program to your website.

Don’t think you would need a backend in this case, if you didn’t want one.

Edit: Whoops, doesn’t look like Pygame works in Pyscript, sorry!

@DEV-MEASTRO I am having trouble understanding: Is your game made in Python and you want it to be in Python, or is it HTML wanting to be run in Python???

OP wants to show his Pygame program in his Flask website.

Oh. Hmmm… So I think you are right with the pyscript as one way. @DEV-MEASTRO why do you want to put it in a website?

Pygame wouldn’t actually work with PyScript. Tbh I don’t see why OP isn’t just using a Pygame Repl.

1 Like

@DEV-MEASTRO Could you create a pygame repl and iFrame it into the website?

Using PyScript I think pygame would work if you put this at the beginning of the script:

import os
os.system('pip install pygame')

I am not sure if that script would help at all but that should get the pygame module on to the pyscript console.

Hope this helps!

-MilesWK

Yeah, that seems to be the only way

It’s just not possible to have Pygame run on PyScript AFAIK. I kinda forgot why.