Issue
A while ago, I created some mini games with python. And now i'm working with html. I know how to link a css file to an html file. But I do not know how to link a python file to some words in an html file.
I have tried to directly href it to my python file like this:
<a href="Alien Invasion\Main\Alien Invasion.py">Play the Game</a>
This is what I've got so far
{% load static %}
<html>
<link rel="stylesheet" type="text/css" href="{% static 'webinfos/style.css' %}">
<ul>
<li><a>Home</a></li>
<li><a>Alien Invasion</a>
<ul>
<li><a>Explanation of Game</a></li>
<li><a>How to play</a></li>
<li><a>Origin</a></li>
<li><a>Play the Game</a></li>
</ul>
</li>
<li><a>Crossy Road</a>
<ul>
<li><a>Explanation of Game</a></li>
<li><a>How to play</a></li>
<li><a>Origin</a></li>
<li><a>Play the Game</a></li>
</ul>
</li>
<li><a>Classic Snake Game</a>
<ul>
<li><a>Tips&Tricks</a></li>
<li><a>Best Gameplays</a></li>
<li><a>Funny Moments</a></li>
<li><a>How to Play</a></li>
</ul>
</li>
<li><a>Other stuff</a></li>
</ul>
</html>
I expected it so that when I click on the words that are linked to the file, it runs the game. But instead, it shows:
Page not found (404)
Can someone help me with this?
Solution
Python code cannot be run in the browser, at least directly. There's just no way. See, it doesn't work like a Flash game does. You won't be able to open a Python file in the browser and expect a full shell to run, as there are no browsers out there that even support anything like that. A user can download a Python file from your website and run it on a local shell, but it is not possible to run anything like that directly in the browser. Granted, there are websites that will let you upload code and see the results, but there's a difference between running code on a remote server and running code in the browser. The latter is impossible.
And in regards to your original problem, yes, you have linked correctly. However, make sure that you have linked to the right file, and that the file is spelled correctly and is in the right directory. Keep in mind that they will only be able to view the code, not run it in-browser. (unless you link to an online REPL or shell, which I highly recommend in this circumstance)
Answered By - WAUthethird
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.