Live data from Hacker News

I only know PHP. How do I write a Web application in Python?

me.veekun.com

91–100 of 196 posts

Re: I only know PHP. How do I write a Web application in Python?

#91
Is there any cheap & easy webhosting available for Python?

Occasionally I get commisioned to build small websites ( I don't want the hassle/expense of having to setup and run VPS/AWS infastructure. I just want to give someone a bunch of files and say "sign up for some cheap webhosting, ask them to give you a DB called X and upload these".

I usually end up just doing it in PHP, but it has always felt like a poor reason to choose a language with so many warts.

Re: I only know PHP. How do I write a Web application in Python?

#92
post #35

I would love to switch to Python from PHP but I can't. The reason is I keep getting told to learn Python 2. Python 3 has been out for ages! Basically I am concerned that I will learn something and create app's which within a year will be out of date. I am confused why Python developers are advocating that newbies learn an old and presumably soon to be legacy version of the language. I remember when this kinda happene…

The differences between Python 2.7 and 3.x are going to be minimal. You can mostly write Python 3.x style code in 2.7 and still have access to all of the libraries that have not ported their code yet.

Re: I only know PHP. How do I write a Web application in Python?

#93
post #10

I'd say the necessity of this post is why PHP is as popular as it is. With PHP, there are no package managers I have to install; there is no template language to learn; there is often no version control; there is no "framework"; etc. You just drop in a .php file and, most likely, it will just run. If I need a quick dynamic page on my server, it's much easier to do this in PHP than in Python or Ruby. Until Python or R…

There appears to be currently ongoing some sort of shift in web development.

At the top end of the scale , people are creating more sophisticated "app like" websites that use sophisticated platforms like AWS and "serious" programming like Scala/Java/Ruby/Python/jQuery etc. Because once you have decided to invest serious money in your web development you want to use the best tech you can and build a very "bespoke" online experience.

However at the lower end, sites that would have 5 years ago been build using static HTML with a smattering of PHP and be run on low end shared hosting are being devoured by various platforms. For example rather than hire a webdesigner you can have a facebook fan page or wordpress blog for free (possibly paying someone to customise the CSS in a template for you). As another example in my area there are various services aimed at the takeaway business that provide a turnkey website with an online menu, opening hours, maps etc.

To be honest, working in the low end of the web dev market has always been a nightmare as this is where you will get shaky clients who can't articulate what they want and hardly want to pay anything for it.

If I was going to go back into website development for a business I would be far more interested in finding common requirements for a particular market segment and building something turnkey to sell to 1000+ customers at $20-100 per month where they can upload their own logo and change a bit of the CSS.

Re: I only know PHP. How do I write a Web application in Python?

#94
post #66

Earlier quoted context omitted.

It's actually easier... $ git push heroku master

That is obviously not sufficent. For using PHP I literally have to tell people to open an ftp GUI client and drag+drop a folder, or do something like: sftp -r website user@host: So, what is the full "this is how you use heroku" I can send to a windows user, who knows HTML and wants to just get started with 'hello world'.

See the Heroku Quickstart: https://devcenter.heroku.com/articles/quickstart

Essentially you sign up for a Heroku account (https://api.heroku.com/signup), and set up the Heroku "toolbelt" (https://toolbelt.heroku.com).

Once that's done, you can run this bash script (https://gist.github.com/2622850) to create and deploy a "hello world" Flask app on Heroku:

  $ heroku login
  $ bash setup.sh helloworld
  $ cd helloworld
  $ git push heroku master
It should return a live Web URL for your app:

  http://strong-stream-5848.herokuapp.com deployed to Heroku
See the Heroku Python tutorial (https://devcenter.heroku.com/articles/python) for details.

Re: I only know PHP. How do I write a Web application in Python?

#95

I really don't think it's worth taking this guy seriously. First he writes a worthless and inaccurate lambast of PHP, and now he's trying to "convert" people to Python by telling us Unicode sucks. Get a life.

> ... by telling us Unicode sucks. Could you tell us where he did this? (I didn't notice it on the first time through; he did say to use Unicode everywhere inside your code, though, and to not do anything rude like converting Unicode to ASCII by stripping non-latin1 characters.)

Right under the big bold "Unicode" header. The very next line is

> Unicode sucks. This is a universal truth.

(In fairness, I think what he's really getting at is that dealing with Unicode in languages that were created before it became ubiquitous sucks, not Unicode itself. But if you start off your discussion of Unicode with the statement that "Unicode sucks", you shouldn't be surprised if people think your beef is with Unicode rather than with the tools we use to deal with it.)

Re: I only know PHP. How do I write a Web application in Python?

#96
post #10

I'd say the necessity of this post is why PHP is as popular as it is. With PHP, there are no package managers I have to install; there is no template language to learn; there is often no version control; there is no "framework"; etc. You just drop in a .php file and, most likely, it will just run. If I need a quick dynamic page on my server, it's much easier to do this in PHP than in Python or Ruby. Until Python or R…

PHP is a template language at heart, so it's a little disingenuous to say that it doesn't force you to learn one, as it does - it's like the erb template language part of rails without the controllers and models. That's fine for what it is, but becomes cumbersome if you want to persist data to the db, handle forms for your models, etc at which point you'd often be better served looking at a framework which does a lot…

I am but an egg. But refactoring badly done projects that were started as PHP seems a plausibly common pattern. If Python or Ruby were simpler to start with, there would be more badly done Python / Ruby code, but at least it would refactor in Python / Ruby.

The core Py / Rb community probably wouldn't use simpler quick-and-dirty setups, they have the skills to the same things better and faster already. But making that pathway available would bring more novices to the language, hopefully growing them into Py / Rb. And it would bring more projects into the fold.

Re: I only know PHP. How do I write a Web application in Python?

#97
post #35

I would love to switch to Python from PHP but I can't. The reason is I keep getting told to learn Python 2. Python 3 has been out for ages! Basically I am concerned that I will learn something and create app's which within a year will be out of date. I am confused why Python developers are advocating that newbies learn an old and presumably soon to be legacy version of the language. I remember when this kinda happene…

> I am concerned that I will learn something and create app's which within a year will be out of date

Don't worry about that. Start with Python 2 and if you ever have to move to Python 3, it will be fairly easy.

The same thing happened in the PHP world during the switch from 3 to 4 and then 4 to 5. The move from Python 2 to 3 will probably be smoother.

Re: I only know PHP. How do I write a Web application in Python?

#99

Earlier quoted context omitted.

It took me a while to get used to creating an HTML file and making part of it executable. How utterly obvious and convenient. Templating systems and MVC frameworks now seem like bureaucracy that solve a purely theoretical problem.

Sure, if all you need is a mildly dynamic page the full blown MVC frameworks that are "standard" for other languages probably seem like bureaucracy to you. But they have their uses, and they also exist for PHP for a good reason. MVC makes massively complicated systems easier to maintain, especially if there's more than one contributor. Example: I'm responsible for maintaining a "classic" ASP project that's evolved ov…

That is of course assuming that the person who wrote the original code actually understood how to use an MVC framework.

It seems to me that most peoples default assumption upon encountering one is to use the Model as a simple abstraction to the DB and stick all of the logic in the controllers (with many controller methods calling methods in other controllers).

Re: I only know PHP. How do I write a Web application in Python?

#100
post #16
post #10

I'd say the necessity of this post is why PHP is as popular as it is. With PHP, there are no package managers I have to install; there is no template language to learn; there is often no version control; there is no "framework"; etc. You just drop in a .php file and, most likely, it will just run. If I need a quick dynamic page on my server, it's much easier to do this in PHP than in Python or Ruby. Until Python or R…

Most of the post _isn't_ strictly necessary. You don't need a database to get your feet wet. You don't need to care about XSS for your first throwaway app (though, arguably, you should). I pimp Mako precisely because there's no separate language to learn: the core syntax is just Python. I tried to describe the _ecosystem_, and I assume any serious PHP application will care about most of the same things. Here's all yo…

I am lucky that I found Flask a while ago, because I was sick of PHP. Flask, jinja2, and uWSGI have since been my best friends.

It took a little while to figure out how to setup a proper web server around those, but the guides are not that complex. Install nginx, darmonize uWSGI with upstart, and configure it. It's funny, in some ways it's easier to use than PHP, because when I am working with the website on my local machine, I can run uWSGI in http mode, no configuration necessary.

The only barrier I see going from PHP to Python or Ruby is managed hosting.

Post reply on HN