How to make a website that's modern with the ability to implement python code into it

Hello I’ve been trying to make a website with the ability to import python onto it and I really don’t know how to do it and I’ve been wondering if anyone else does but I want to make sure it’s got an actual URL name and looks good.

Thanks
zm476

Hi again,

Not sure what you’re asking. One lesson I learned at a company where I once worked is this:
If you’re developing something new, start from the end. Start from the end-user experience that you want to create or support. Tell a story in your own words about what the user (of your website in this case) will experience or be able to do. What is your story for this?

If you don’t have a clear story yet - and just want to look at sample code of how to develop some web site in Python, I would recommend looking at Flask examples: Welcome to Flask — Flask Documentation (3.0.x)
There are other tools/platforms available, but I think Flask is the most simple and user-friendly for beginners.

2 Likes

Can you describe what you mean here? If you’re talking about a site like
Jupyter notebooks where you’ve got a web interface where people can type
and run Python, keep in mind that running user supplied code is a
massive security problem - Python does not lend itself to sandboxing to
make things safe to run untrusted code. Sites like Jupyter have
something robust behind the scenes, maybe a virtual machine or a Linux
container sufficiently isolated from the main system.

If this is just a demo for your own use that’s one thing, but exposing
it to other users is a risk.

That said, you can probably use a toolkit like Flask to run a basic demo
which presents a web form in which to enter some code, and writes that
code to a file to load and execute. But do not expose that form to
people who aren’t you until you understand the security issues.

Whatever code you load-and-run will be running as you (or whatever
user runs your little web server) and will have the same access to
your files as you do.

Cheers,
Cameron Simpson cs@cskk.id.au

@zm476 If someone wants to write a novel, they first need to learn to write words. To write words they first need to learn the alphabet. I have the impression that you want to write a novel (do ML, develop a web site), but have not quite mastered the alphabet (basic Python, basic OS concepts, html?) If I am correct, then you are setting yourself up for disappointment.

If I may suggest something that is “something completely different” - intellectually challenging, perhaps, depending on what kind of math background you have, but still doable (hopefully) - have a look at:

This comes with Python source code - pretty dense code, but more self-contained than ML-code or web-dev code.

You could then consider the question: OK, suppose I had to write my own code from scratch, not using pygame, how could I totally simplify this and still get something interesting? (Answer: You can. Hint: Work on a fixed square grid of cells filled with either ‘@’ or empty. Whenever a new point is added, find the closest cell in the grid and fill that. At the end display the whole grid. Even as pure ascii representations those fractals look beautiful.)
Or you could consider the question: Ok, I’ll just start with this given sample code. How can I modify it so that I start with a square instead of a triangle (etc)…
(If this is still too difficult - have a look around at that site - There is more Python code there.)

Exercises like that are like writing words. When you can do that, you may be ready to move on to web-dev or ML samples :slight_smile:

Okay I’m going to do some research

I do know alot of the basic python commands it is just a matter of learning about all of the usually used libraries

The libraries are always the difficult part. Apart from the standard library modules, there are also some external libraries that are kind of indispensable (for instance, requests for any kind of http requests or numpy and pandas).

For clarity, requests is for making HTTP requests i.e. fetching
things off the web.

You’re writing a server, so you need something for receiving requests.

The stdlib contains a basic HTTP service:

but you’re probably better off with a framework:

  • flask: Flask · PyPI
    simple and easy, good for simple things
  • cherrypy, also a simple web service
  • django, enormous and complex, for complex web servers with nontrivial
    database backends

I recommend giving Flask a try for your stuff.

Cheers,
Cameron Simpson cs@cskk.id.au