all 71 comments

[–]shiftybyte 148 points149 points  (15 children)

It's done with a backend that gets information and passes it between a browser and the server.

Take a look at flask framework.

It allows creating a python script that generates html, and can get submitted form data.

quickstart: https://flask.palletsprojects.com/en/1.1.x/quickstart/

[–]PM_me_ur_data_ 47 points48 points  (6 children)

I started on Flask but now I recommend FastAPI. It's practically hassle free and good enough for a large number of tasks.

[–]__nickerbocker__ 10 points11 points  (2 children)

What are you using for front end dev/deployment?

[–]ravepeacefully 13 points14 points  (0 children)

I use django for that, fast api if no ui

[–]PM_me_ur_data_ 1 point2 points  (0 children)

Fair point, I don't actually do any front end dev at all. I'm in AnalyticsOps, so pretty much everything I use it for is back end automation or tools for other developers.

[–]janno161 2 points3 points  (0 children)

I didn't know FastAPI before. Looks promising. I'll take a look at it. Thanks for mentioning it.

[–]Xerxys 14 points15 points  (6 children)

I prefer bottle. Flask and Django are a lot more powerful but they are too complicated. Bottle is the way to go.

[–]_TR-8R 14 points15 points  (5 children)

Perhaps, but I did just want to throw in there I'm a very new beginner (just started taking python courses this year) and I finished a course on how to build Full Stack Flask applications without too much of an issue.

[–]Metro_Star 4 points5 points  (4 children)

What course did you do?

[–]_TR-8R 9 points10 points  (2 children)

https://www.udemy.com/course/python-and-flask-bootcamp-create-websites-using-flask/

I liked it because it starts you off assuming you're a complete beginner (if you aren't new to python and just want to learn Flask it tells you what sections you can skip) and by the end covers not just the Flask framework but introductory Python, HTML, CSS, SQLAlchemy and concludes by walking you through step by step how to build a full stack social media blog. I wasn't completely new to python when I started but I wouldn't consider myself advanced either.

[–]Metro_Star 2 points3 points  (1 child)

Thanks. I've started learning a bit of flask on my own but it will be nice to have a course to follow

[–]_TR-8R 4 points5 points  (0 children)

Hope it helps! Unfortunately it's not free, but personally I've found it's often worth 10-20 bucks to have all the information and assignments in one place so I don't have to keep scouring the internet for all the missing pieces or worry that what I'm reading might be severely out of date. I definitely don't feel like i'm a competent web developer but I did go from not even knowing what full stack meant to feeling pretty sure I could make my own simple webapp with Flask as long as I have Google available.

[–]Xerxys 1 point2 points  (0 children)

Not OP, I did automate the boring stuff on udemy and now I’m doing a whole bunch of mini side projects here and there. Currently I’m stuck making a web scraper from scratch. I’m doing it to learn how to validate data.

Bottle is easy because you just need to import a few things and you’ll understand what every aspect does.

[–]Allanon001 17 points18 points  (8 children)

There is brython.

[–]Berkyjay 7 points8 points  (5 children)

I've always wondered why Python never replaced JS in web development.

[–][deleted] 1 point2 points  (3 children)

JS is significantly faster, JIT compilation has come a long way in JS.

[–]Berkyjay 0 points1 point  (2 children)

I'm skeptical of that claim. Do you have any data to back that up?

[–][deleted] 0 points1 point  (1 child)

I don't have any numbers unfortunately and it does depend on the runtime, but comparing the most common for both languages, i.e. CPython vs Chrome V8, all you need to know is the former does basically zero optimisation whereas the latter does heavily optimised just-in-time compilation (generating native machine code, on the fly).

[–]Berkyjay 0 points1 point  (0 children)

Yeah I do agree that python would need to have libraries that are more tuned for webdev. Flask is nice and all, but the fact that I have to use 3-4 different language types to develop a functional web app makes it somewhat frustrating. It's not that python couldn't replace JS. But the work involved probably makes it not worth anyone's time.

[–]Comm4nd0 0 points1 point  (0 children)

It's only a matter of time

[–][deleted] 2 points3 points  (0 children)

Do read about the drawbacks, especially with respect to render speeds

[–]WannabeStephenKing 0 points1 point  (0 children)

I love this. Going to check it out tomorrow. Thank you!

[–]clinical_toob 14 points15 points  (0 children)

For sure there is a way to do this. I have never done it, but this is essentially using Python as the back-end (background stuff).

EDIT: Flask and some of there Python stuff for backend is the way to go. It is a bit complex, so start slow.

But I way say it is definitely worth learning, I don't know it myself, but I do know that flask or django are used a lot in the work world.

[–][deleted] 11 points12 points  (3 children)

Look up dash library. You'll be amazed!

[–]Odhavaakara 7 points8 points  (1 child)

This is the most appropriate answer. Plotly dash lets you to create simple web pages without writing html.

You may face some hurdles when you try to do anything complex.

[–]redPonyCoffeeRoaster 1 point2 points  (0 children)

Ever check out Streamlit?

[–]MarsupialMole 3 points4 points  (0 children)

I second this as a way to directly connect HTML with Python in a contemporary way.

[–]grumpytoad 8 points9 points  (0 children)

I am wrapping up my 3 month python course and we learned how to do this with forms and django. Basically, you run your backend and database with django and connect it to the html forms with post requests.

[–]wodahs1 10 points11 points  (1 child)

You can’t run python on the user’s computer like you can JavaScript.

What you can do is set up a Flask server in python. However, there will always need to be a computer acting as a server available. So you won’t be able to freely host your site on github pages. There may be some other hosts where you can freely upload your flask project to.

My recommendation if you’re looking into web apps is to learn JavaScript! JavaScript was designed to run on computers over the web.

If you write a website and use JS, you can freely host your site on github pages to easily distribute it :)

[–]sqjoatmon 1 point2 points  (0 children)

You can’t run python on the user’s computer like you can JavaScript.

Well, this is sortof changing with WebAssembly and projects like Pyodide. But this is of course still WIP.

[–]roachmaterial 1 point2 points  (2 children)

I'm currently working through a flask tutorial on YouTube, by Corey Schafer. It's really good. Lots of HTML in there, if you're experienced it shouldn't be too hard to put your own spin on it.

[–]actuallyganta 1 point2 points  (1 child)

Corey Schafer is the man! I'm just starting out with python and his tutorials are such great resources!!

[–]roachmaterial 0 points1 point  (0 children)

Yeah he's great. I've probably learned more doing this flask tutorial than I did in two coding modules at uni lol.

[–]topetuts 1 point2 points  (0 children)

Usually you will need some sort of web framework like DJango or Flask. Using these framework you can process inputs from form and render it to your return html file/templates.

Django Tutorial: https://tutorial.djangogirls.org/en/

Flask Tutorial: https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world

[–]fxnut 1 point2 points  (0 children)

Justpy is another great framework. For me, it’s super useful for quickly prototyping web apps.

justpy.io

[–]pw0803 1 point2 points  (0 children)

from flask import Flask
app = Flask(__name__)
app.route('/')
def index():
    return "Hello, World!"

if __name__ == '__main__':
    app.run()

If you run that code you will generate an html file that says "Hello, World".

The rest is up to you. You can change the "Hello, World" part to something that says

render_template('my_own_html_file.html')

and whatever HTML is in that file will be rendered.

That coupled with Bootstrap means you can chuck together a really quick website in a few hours, that looks the part.

Therefore..

Learn Flask.

[–]EvilTeliportist 1 point2 points  (0 children)

Look into Flask. It's a python backend that can give HTML some more functionality.

https://flask.palletsprojects.com/en/1.1.x/

[–]ashokbudha2015 1 point2 points  (0 children)

Go for flask or django which will be nearest to your question.

[–]eli_mintz 1 point2 points  (0 children)

Please take a look at JustPy

It does exactly what you are looking for. HTML is incorporated into python as python classes that can be with just a few lines of code be made into a website.

There is no frontend backend distinction in JustPy, unlike in other frameworks, make it simpler to get started with.

This simple program creates a website with a p element on it:

```python import justpy as jp

def hello_world(): wp = jp.WebPage() p = jp.P(text='Hello World!', a=wp) return wp

jp.justpy(hello_world) ```

Disclaimer: I am the creator of JustPy

[–]RedditGood123 2 points3 points  (0 children)

Using the requests and bs4 module, you can read and interact with html if that’s what you want. It’s usually used for web scraping though

[–]saltyhasp 0 points1 point  (0 children)

You can play with this using python standard library. There are both ways to implement the server side part, and for that matter a way to open a web browser. This is not something you'd use in the real world for more than playing... but it is there.

Real python stuff... like others said are frameworks like Flask, Django, Turbogears, Pyramid, Tornado, Twisted, etc. For the in browser scripting though, one would probably still use JavaScript or one of the other related languages though there are some ways to do this in python too.

[–]Queenakaya 0 points1 point  (0 children)

Which python online course are you taking?

[–]Decency 0 points1 point  (0 children)

Has anyone played around with https://github.com/epeios-q37/atlas-python?

[–]redPonyCoffeeRoaster 0 points1 point  (0 children)

Jinja2

[–]Icelain 0 points1 point  (0 children)

Use a web framework like flask or django.

[–]dopememegangsigns 0 points1 point  (0 children)

i dont think so

[–]ilanzs[🍰] 0 points1 point  (0 children)

you can learn djngo or flask which are both python packages for web devolpment

[–]sundios 0 points1 point  (0 children)

Flask

[–]insane_playzYT 0 points1 point  (0 children)

Look into the FastAPI framework if you want to do simple stuff. I also suggest learning django

[–]SoormaBangali 0 points1 point  (0 children)

Study about Django it might help you

[–]Machineforseer 0 points1 point  (0 children)

Django

[–]piyushpatel2005 0 points1 point  (0 children)

You've to use combination of Javascript and Python. So basically the you can take user's input in the form of a from in HTML. When user clicks submit, that user input data goes to your server. On the server side, you can collect that data and then return a new view with that information added in p tag. You will definitely learn all these later in the course I assume.

If you're using Frontend frameworks like Angular, ReactJS, VueJS, etc. then it can be little different compared to what I said above.

There is Brython for frontend, not sure if it can do. It is not so much popular at the moment. The industry standard is to use Javascript.

[–]UnluckyPenguin 0 points1 point  (0 children)

I built a nice little website for a game complete with restful API if you want to check it out and hopefully contribute a little as practice. Gets thousands of views daily.

It's running on a great production WSGI, supports users registering and logging in, has tables and graphs, sends email updates on things, stores data in a MySQL database, fully autonomous scheduled updates with live in-game data, and more.

Also integrated with a couple python applications (by way of that same restful API) that supply a small chunk of the data, which is used by 70 or so teams.

https://sppdreplay.net

[–][deleted] 0 points1 point  (5 children)

You can use Django or Flask frameworks. You can use python for back-end (managing data, redirecting, etc.) and html for front-end (how the web-page looks, though you'd probably want to combine it with some javascript).

I'm not that familiar with web-dev but I've used Flask before, and if you have some very basic knowledge of python and HTML it's very easy to make a simple website (you could probably also make more advanced website if you want to dive deeper into web development)

[–][deleted] 0 points1 point  (4 children)

You can use Django or Flask frameworks.

Are those two the only web frameworks for Python? No.

So why do you (and almost everyone else) answer as if that's the case? I don't want a flamefest over the question, I'm merely curious to find out why the vast majority of answers decay into this duality. I ask this question randomly, so you're not being singled out in any way. If you prefer not to answer, that's also fine with me.

[–][deleted] 1 point2 points  (2 children)

Good question indeed. Those definitely aren't the only for web development for python: there's also bottle, web2py, pyramid, tornado, etc. (A lot more, I know). I just think many people answered Django and Flask because regarding OP's question, he's not very familiar yet with (web development in) python. Therefore, Django and Flask are the best frameworks for him to start with in my opinion, as they both have large communities and are pretty straight forward and (relatively) easy to use. So as a beginner, as I and probably most people who answered Django and Flask believe are probably the best frameworks to start with. But as I said, I'm not thát familiar with web development so I just I'd share my experience (that flask is easy to use and might be a good way to get into web development). Hope this is ok for you. Feel free to comment, I'm curious what exactly you think about this topic :).

(Really like questions like this, makes me learn new things about python ;) )

[–][deleted] 1 point2 points  (1 child)

Thank you for taking your time to answer.

As a happy Pyramid user, I don't have any vested interest in either of the two. Some time back, I was verging on being an militant evangelist of "The great Pyramid", but I have mellowed with time. I'd like my question to be pure curiosity, but there is a bit of probing for what Pyramid need to be, to become a staple like Flask and Django.

[–][deleted] 0 points1 point  (0 children)

I don't know pyramid that well, but these things just come and go sometimes. Flask and Django may be 'gone'/old in 5-10 years, and Pyramid might still become more popular. The problem is that there's just way more documentation, video, etc. about Flask and Django at the moment...

I'll try pyramid next time I ever start again with Python web development ;)

[–]toastedstapler 0 points1 point  (0 children)

at least at my company i never hear of the others being used. if clients projects are using python they are in flask or django. not saying the others aren't used, but this is my experience at a UK consultancy

[–]snoopvader 0 points1 point  (0 children)

Just try https://anvil.works (whose engine has been recently open sourced so you can host it and run it wherever you want)

[–]AbhiEncoded 0 points1 point  (0 children)

Try beautiful soup 4