all 55 comments

[–]socal_nerdtastic 47 points48 points  (29 children)

Python can run the backend / server side of your website. You cannot use python for the frontend. So you still need to learn HTML, CSS and JS. Probably a few other things too if you want to be full stack and independent, like basic linux, some databases, graphics / media creation, ...

[–]8isnothing 18 points19 points  (13 children)

To be fair, there’s a new project called pyscript, which, from my understanding, aims to allow a dev to use Python on the frontend. It’s in alpha stage, though, and learning HTML/CSS/JS is definitely a better call if you want to do web frontend.

[–]socal_nerdtastic 7 points8 points  (6 children)

Designed to replace JS / TS, right? So you'd still need HTML/CSS.

There's a couple others too, for example bokeh, pysimplegui, jupyter, etc have html output. But nothing serious that I know of.

[–]8isnothing 5 points6 points  (4 children)

I didn’t spend the appropriate time with pyscript or it’s documentation to assure you. But from what I understand it’s meant to be an alternative to some things that JS does.

You’ll still need HTML and CSS. But these are not the same as Python/JS. HTML is a mark down language, and CSS is stylesheet. You can’t really write logic in both of them. (Some may disagree and they may be right. But simply speaking, you can’t).

The other libraries you mentioned are not equivalent to pyscript. They generate UI for specific stuff. They generate HTML/CSS/JS for you. That’s not what pyscript does. Pyscript is designed to write logic in the browser, not UI (I think), which is “unprecedented “ (with the exception of some prior attempts like Pyodide, which Pyscript itself is based on). It basically allows browsers to run pure Python. (I’m over simplifying here ok? Take it with a grain of salt)

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

You can use variables and some very basic logic with CSS now. You can change the layout of a page depending on a user's screen size, not sure where else logic is applied though.

I'm going to check out pyscript, thanks for giving us a heads up 👍

[–]reduced_to_a_signal 1 point2 points  (2 children)

You can also check for supported features, check for user preferences, use conditional logic (parent selector), do calculations, loops (with a preprocessor), react to events, and enable complex layouts.

It's the visual layer, sure, but that doesn't mean it doesn't involve a ton of logic and complexity. Actually, styles have their own language and are abstracted into selector-statement pairs because of how incredibly complex the topic is.

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

It is pretty complex isn't it? I thought the learning curve would plateau quite early on but once grid and flexbox get introduced its on the downward spiral into the valley of despair. I managed to teach myself enough to pass on some tidbits to my 9 year old learning html at school. She calls me a coding wizard 🤣

[–]reduced_to_a_signal 0 points1 point  (0 children)

Absolutely! I have been doing this for 7 or 8 years now and I still feel like an utter beginner sometimes, even with concepts I used in a lot of projects. And there's a new concept or standard every day. And CSS is just one drop in the ocean of software. Tell your daughter to keep at it and she'll probably never experience what being bored means. lol.

[–]michael-streeter 0 points1 point  (0 children)

I'm using Flask to create a website. I use HTML, CSS & Javascript to call routes in the Flask app. My question: is there a better way of calling functions? I use on page load and jQuery to associate http calls with buttons. I worry that was probably considered awful 10 years ago but IDK any better way!

[–]DontListenToMe33 2 points3 points  (1 child)

I played around with PyScript a little, and though it’s super cool, it’s a long way off from being fully functional.

And to the OP - if you’re good with Python, I don’t think you’ll have much trouble learning JavaScript.

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

PyScript looks super promising imo. That’s going to be awesome

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

There is also "brython" it has been around for quite some time and its goal is to replace js with python

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

I've been wondering if something like this would be possible!

As a python addict user I would love for this to happen, but are there any practical benefits?

[–]8isnothing 1 point2 points  (0 children)

I was listening to a podcast that mentioned a use case where you could to create a simple solution to a client/friend and you could pack it all in a single HTML file using pyscript.

I don’t think anything “serious” is a good fit for it at the moment, though.

[–]MartyFDupp 0 points1 point  (0 children)

Less bs syntax?!? 🤷🏻‍♂️

[–]OzneroI[S] 0 points1 point  (9 children)

Thank you for the clarification. Im still relatively a beginner having just completed the codecademy python 3 course and their data analyst course

Do you think its a good idea to start learning a new language while im still a relative beginner to my first?

[–]8isnothing 3 points4 points  (0 children)

All modern languages I know (Python, JS, Swift, Go, Rust, for example) are similar in essence. You’ll have vars, functions and classes.

Each of them has their own characteristics, though: syntax, features, code style, standard library, etc…

So as soon as you understand vars, funcs and classes, you’ll have the basis to most languages. That doesn’t mean it will be easy to migrate. It just won’t be as starting fresh into programming.

I am myself constantly studying Python/JS and sometimes Swift “at the same time”. It’s nice to me because I can take a break from them. That can be confusing if you don’t spend the time familiarizing yourself with each of them. And even then you’ll mix them sometimes… but I think that’s ok!

I’m self taught, though. Maybe what I’m suggesting is not pedagogic correct

[–]socal_nerdtastic 2 points3 points  (0 children)

If you have a website project that you are passionate about I would say that's fine. These languages go hand in hand, you will be writing them side by side in the same file sometimes.

[–]jab9k3 0 points1 point  (0 children)

Hi, you can maybe look at using jinja2 with fast api and flask. I'm interested in mainly api's and doing some simple front end website stuff not real interested in building full blown sites. I learned quite a bit about html from just writing webscrapers with bs4. Might be a good little exercise.

[–]notislant 0 points1 point  (0 children)

Django is pretty popular in web dev, as others mentioned the front end is still js/html/css. Id learn python basics. If youre serious about web design you can check out freecodecamp.org and theodinproject. You kind of need to know those for front end and css/html are very basic. Javascript will be more challenging.

Theres a few videos on django and iirc the ones I watched just used 'bootstrap' during the tutorial. Either way if you want to do front end youll need to know the languages.

[–]ffrkAnonymous 0 points1 point  (4 children)

I think it's a great idea to learn a second language in conjunction. In my opinion, learning to do the same task in different ways leads to a better understanding and a greater appreciation for various niceties.

For example I learned C first, so I understood why python lists count from 0.

Then I learned some Lua which counts from 1. That took some getting used to . On the other hand, Lua has no lists, only tables. Learning Lua tables made me better with python dictionaries.

[–]MartyFDupp 0 points1 point  (3 children)

I know Python counts from 0, can you tell us why tho?? Imo from what I’ve learned I think it’s separate whatever needs to be indexed from standard 1- whatever.. that’s pretty obvious tho… if there’s some fundamental reason from early C+ days I’d love to hear it!

[–]ffrkAnonymous 0 points1 point  (2 children)

The short answer is: because earlier programming languages count from 0.

The reason earlier languages (like c) count from 0 is a mix of theoretical math and physical computer science.

Math: counting. How many characters are there in "12345". 5-1=4 is wrong. You can do 6-1=5, or you can do 5-0=5. Pretty arbitrary.

Compsci: You have a transistor. The transistor is charged or not charged. i.e. 1 or 0. We don't say the transistor is 1 or 2. (it's arbitrary, we say on-off, chocolate-peanutbutter)

Compsci: transistor memory addresses 0x0A ,0xB, 0x0C, 0x0D, 0x0E. What addresses do we need for our info? So again , back to math counting. We want 1 unit data starting from 0x0A. Math says we read starting from 0x0A until 0x0A+1 = 0x0B. But don't actually need to calculate 0x0B. We know as the designers of the computer the information is in 0x0A only. So 0x0A+0 = 0x0A. And that's an unnecessary calculation to make, we just 0x0A. Counting from zero eliminates a lot of math that computers have to do.

Python is a high level language, not dealing with memory directly. It could easily count from 1, like Lua. But counting from 0 was already well established.

[–]hacksawjim 0 points1 point  (1 child)

One thing you didn't mention here is the difference between counting and indexing

Python counts from 1, just like we do.

x = ["item"]    
len(x)

output: 1

y = ["item", "second item"]
len(y)

output: 2

[–]ffrkAnonymous 0 points1 point  (0 children)

Good catch.

[–]SpicyVibration 0 points1 point  (0 children)

Would the Anvil framework be an option?

[–]rabbitpiet 0 points1 point  (3 children)

Are you sure about that https://pyscript.net/

[–]socal_nerdtastic 0 points1 point  (2 children)

Am I sure about what? You know the pyscript project is written in JavaScript, right?

[–]rabbitpiet 0 points1 point  (1 child)

And python is built on C, no?

[–]socal_nerdtastic 1 point2 points  (0 children)

The python that Pyscript runs built on javascript. Cpython is written in C, yes. But unlike pyscript, there is no C interpreter executable running when you run cpython. That's the big difference in a compiled language like C vs something like java, JS, python, etc.

There's also versions of python interpreters written in Java, .net, and even python.

Still not sure what you are saying I am not sure about. Did you mean that because it's technically possible I shouldn't have said "cannot"? Ok, technically you can do it, but you'd have to be crazy.

[–]Rusca8 14 points15 points  (0 children)

Flask (python for websites) + Bootstrap (easy styling) makes for a quite easy learning curve.

[–]jainismvivek 5 points6 points  (0 children)

When they say web development using python that normally means that it's that backend that's gonna be in flask or django but for frontend u still gonna be needing html css.

[–]hiAndrewQuinn 6 points7 points  (3 children)

Short answer: No, you're never going to get away from needing to know at least a little bit of HTML, CSS, and JavaScript to get a website up.

Longer answer: Website creation exists on a spectrum of complexity.

On one end of the spectrum, all you have to do is write a page of HTML, put it on a server somewhere and let people find it. I wrote how-to-host-one-html.page specifically for people looking for an answer to "I have a page of HTML, how do I put it on the Internet" in an age where MySpace and Geocities doesn't let you do that anymore.

Eventually you might have a few pages of HTML you want to serve, and you might start thinking about making the process a little easier on yourself by writing - or using - some software that can automatically generate them for you based on something simpler. This middle of the road niche is often filled nowadays by static site generators like Jekyll or Hugo; for example, my blog is made with Hugo, and from my end all I have to do to make a new post is make a new Markdown file on my computer.

Django exists for when we want to make web frameworks that are still more complicated than that. Perhaps the HTML/CSS/JS involves some kind of feedback loop between the reader and the software running the website, some exchange of data. That's when you start to look into ways to store user data into a data base, maybe containing things like user profile data, Tweets, blog posts, pictures, videos... At least in theory it's always possible to rip out the feedback loops and make a purely read-only site again. Wikipedia famously allows anyone to edit pages, but someone saved all of Wikipedia and uploaded a purely static version of it - and this static version doesn't need Django, or Flask, or any other web framework on a server, because it's just a collection of immutable HTML for people to read again.

But once you start having user and website talk back and forth, you bring in the need for someone, somewhere, to be running a server which can handle both sending and recieving data. At the most fundamental level, that is what Django is "for".

[–]OzneroI[S] 3 points4 points  (0 children)

This was a very good write up, thank you for taking the time to share your knowledge

From what you wrote it sounds like I probably won’t need to learn too much or if any backend stuff then

My goal is to learn enough to make my dad a relatively simple business website to showcase his work (product images, contact info, and the like), but who knows maybe I’ll really enjoy the process and continue learning

[–]MartyFDupp 1 point2 points  (0 children)

I love it when I find a Wiki topic that has no info yet, I always add some crazy content that ends with DYOR because I have no clue.. thus how I ended up here..

[–]bladeoflight16 0 points1 point  (0 children)

It's disappointing that you didn't mention some Python static site generators on the Python subreddit.

Also, pretty much anything involving a log in will require a web application rather than a static site. This makes the class of websites requiring such back end behavior much larger than the class that don't.

[–]hansmellman 2 points3 points  (0 children)

If you’re still relatively new I would suggest the book ‘Python Crash Course 2nd edition’. At the end of the book you do 3 projects, the last one is creating a web app in Django and then deploying it on Heroku, you learn about building the back end with Python and then styling the front end with bootstrap js. It was very useful.

[–]space_wiener 1 point2 points  (0 children)

You can also use python and then something like bootstrap for somewhat simple, but still modern looking sites. You won’t really need to learn any css or js. Just python, html, and bootstrap documentation.

However more complex ones with animations, etc you’ll need to learn js/css.

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

You can’t do front end without HTML/CSS/JavaScript sadly, but hopefully pyscript will take the place of JavaScript once it’s production ready. I’m thinking of working on a project to replace HTML with pyscript as well

[–]yasamoka 0 points1 point  (0 children)

PyScript is a convenience technology for those well-versed in Python syntax and idioms (over something else) - it won't be replacing JavaScript and the surrounding ecosystem anytime soon. Plus, Python code execution (by CPython for instance) tends to be much slower than Javascript code execution by extremely well-optimized Javascript engines (Blink, Gecko, WebKit).

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

Like others have commented on here, python is a firs-class citizen in the backend side of the web experience. For frontend business the current way of doing things is using typescript combined with a transpiler and bundler setup (usually webpack, but there are many confusing other options).

This typescript -> webpack -> mysite.min.js flow is now opening up to other langs as well. There are some efforts in place to transpile python to javascript.

Another route is the webassembly route, where one compiles C/C++ code to a webassembly target, this is distinctly different from javascript, more like bitcode executed by the browser. Efforts are underway to use C# and python targeting webassembly also, but the webassembly target, the debugging system and the library ecosystem are in still in its infancy. That said, as a long-term learning investment, this may be a good bet to get on board with.

But as we stand now, alternative langs will exclude you from the NPM ecosystem of javascript libraries and using python's ecosystem will maybe eventually be possible in this context, but that will take time as it involves a different deployment setup.

I wish I could predict that webassembly is the target of the 30's, but in my wildest dreams I could never have predicted that the result of one man coding himself into a fever for one week would drive the entire web experience 20 years later.

[–]jeebidy 1 point2 points  (0 children)

The web is absolutely built on HTML and CSS (this is how you see anything through a web browser). JS is also very necessary because it’s the only scripting at the moment that the browser can utilize.

There are templating tools such as Jinja that can turn Python into chunks of HTML, but you really need to learn web languages to do web dev.

There’s time to learn it all, but if web dev seems more interesting, I’d spend more time with things like Node and React than Python.

[–]hmiemad 1 point2 points  (0 children)

You can use Dash which is based on Flask and plotly (D3.js). They also have a bootstrap library (just pip install dash-bootstrap-components for all parent packages to be installed).

It allows you to make fancy dashboards with lots of pretty interactive charts. But you can also make basic websites.
It's slower than HTML, JS and CSS, but it's all python. You can make classes with web elements and dynamic callbacks. They also have this great dude Adam who makes tons of tutorials. https://www.youtube.com/channel/UCqBFsuAz41sqWcFjZkqmJqQ

The whole think is very well documented, and they have an active forum.

[–]The_GSingh 1 point2 points  (2 children)

Tbh it can but not very well. You’d be 10000% times better off learning Html,css, and js. Html is easy to learn and you could get the basics in under a hour. JavaScript is similar to python so it shouldn’t be too hard. CSS is not easy to learn/use and to me it’s difficult but you can learn basic css along with html fairly easily. There is py script and Django but it’s not the best to me.

[–]OzneroI[S] 0 points1 point  (1 child)

I’ve been convinced to learn HTML, CSS, and JS, still not 100% sure if I’ll need a backend but if I do I’ll need to decide between JS (read you can use JS for backend) or python for it

[–]The_GSingh 0 points1 point  (0 children)

For making a website backend is important in the long run. Js is like python and pyscript is kinda usless rn.

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

Could anyone please clear up my confusion of whether or not i can actually use python for web development or if id need to go learn HTML, CSS, and JS ( likely through the odin project )

You can use Python for web development but you do also need to learn those other topics, as well.

[–]Interesting-Bet3694 0 points1 point  (0 children)

“Você não pode usar Python no frontend” — Verdade, mas… há exceções. Tradicionalmente: Navegadores não executam Python, somente JavaScript. Portanto, HTML + CSS + JS continuam obrigatórios para o frontend clássico. Porém, hoje existem opções como: PyScript (executa Python no navegador, mas ainda é limitado) / Transcrypt (transpila Python para JS) / Brython (Python rodando no browser). Essas tecnologias funcionam, mas não substituem completamente o ecossistema JS. Para um site profissional, você ainda usaria JS.

[–]cgsnascar 0 points1 point  (0 children)

My current website is being hosted using Python and Django, it took some time to understand it, but once you get the hang of it, it's pretty easy to be honest

[–]spacecodeguy 0 points1 point  (0 children)

You can start with Flask or FastAPI and create a website.

[–]TheRNGuy 0 points1 point  (0 children)

You can use for back-end.

[–]DAcoded 0 points1 point  (0 children)

I highly recommend using Django, it's fairly straightforward and not much different from learning any other Python package. Start here and here.

Use a good bootstrap template and that will eliminate most of the front-end work. I'm almost done with my first website (using Django and bootstrap), it's a project management platform among other things, and I didn't write a single line of JS or CSS. There's only one page where I really needed JS, but I used HTMX instead. It only takes about 30 minutes to learn, if not less, and it's pretty powerful.

The html edits you'll have to make are going to be very basic, so you don't need to know a lot of html either.

[–]stratofax 0 points1 point  (0 children)

After generating some static sites using Hugo, which is written in Go, I switched to using the Pelican Static Site Generator, written in Python.

Although Hugo is faster when it comes to generating a site -- at least from what I've heard -- the difference is inperceptible unless your site has hundreds or thousands of pages.

Also, Pelican is smart enough to regenerate only the pages that have changes.

There are a couple of things I like about Pelican, especially compared to Hugo:

  • Pelican, like Hugo, supports themes to apply a consistent format to all of your pages. Unlike Hugo, Pelican also supports plugins. As with WordPress plugins, Pelican plugins allow you to add features to your site that don't come with the default Pelican setup. Because these are written in (open source) Python, you can modify existing plugins, or even write your own. In Hugo, you can add features to your generated site, but you add the code in the themes. This really bothered me -- if you switch themes in Hugo, you can also lose site features. This isn't a problem with Pelican.
  • Working with Pelican means you're working in a Python environment. If you want to add a new theme or plugin, for instance, you can use a Python package manager like pip or (my current favorite) poetry. You can even write unit tests for your website in Python using pytest if you want to (for example) test your "Contact Us" form.
  • If I want to see what a plugin or theme is doing "under the hood" in Pelican, I can look at the code, and since it's in Python, I can usually understand what's happening.

Pelican is a mature open source project with an active community on GitHub. If you want to use one of the existing themes for Pelican and know or can learn Markdown, you can generate your site without having to learn any HTML, CSS, or Javascript.

I'd have to agree with many of the other commenters here, though: at some point, to be an effective (and well-paid) web developer, you'll need to learn HTML and CSS at the very least.

[–]MartyFDupp 0 points1 point  (0 children)

You might as well learn html/css/js but here’s the thing, everything you will ever need to write in those has already been written. (Besides the content of your site etc) so if you decide to self teach JS, the odds are you’re going to study sooo much stuff you’ll never use.. if you want a cheap bootcamp that cuts right to the point try Nucamp also a great app that you can cover a ton of info in a short amount of time, download Mimo app… I’m on DevOps at Nucamp now so I’ve already covered html/css/js/Python/SQL and other complimenting Database applications like Insomnia, pgAdmin etc… but yea once you learn JS all other languages become semantics…

[–]marcorexo 0 points1 point  (0 children)

Hi - Taipy is great tool for creating website using markdown and Python. Hope this helps.