Live data from Hacker News

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

me.veekun.com

71–80 of 196 posts

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

#71
post #60
post #16

Earlier quoted context omitted.

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…

Also, http://pow.cx/ (Ruby I know, but it shows such things can be done.) Also the argument of python/ruby requiring lots of configuration while php would not is just plain bullshit. Making PHP run with Apache (esp. on a windows machine) without stuff like EasyPHP (and this is where you stop comparing apples to oragnes) is by and large tough on the beginner.

Indeed, I would say setting up PHP and Apache is usually more work than setting up Ruby or Python behind nginx.

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

#72
post #63
post #52

Earlier quoted context omitted.

CGI scripts have much of PHPs simplicity. You can just drop in a executable file, and depending bit on server configuration, it will just run. With Python a basic hello world would look something like this: #!/usr/bin/python print "Content-type: text/plain" print "" print "Hello World!" So 3 lines of "boilerplate", and then you can do anything you want. No extra packages to install or languages to learn. No framework…

It's a good point that of course python web apps don't have to be complicated. But what you're describing is also not the same as PHP.

plus you can not just mix html and python code, which might not be a good practice, but is incredibly useful for something quick and dirty.

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

#73
post #67

I was thinking this could redeem the author's credibility a little after the PHP rant, but the irrational hatred for Cheetah sounded very familiar. I only used it in one project, a few years ago, but there's really no bad thing about it I couldn't say about any other templating system in any language I ever tried. I wouldn't really take offense with that, but while the XSS chapter still has some points, the Sanitizin…

Explaining why what he does not like about MySQL would have been moving too far from the subject of the article.

And I liked the sanitizing chapter. It explains well why "sanitizing" is a misused word, which should be avoided. Almost always when I see people call it "sanitizing input" they do not seem to know how to handle input correctly.

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

#74
post #53

I've seen Flask mentioned here few times. Is Flask better than Bottle?

In my humble opinion.. Yes. I feel bottle sacrifices just a little too much for the sake of being a single file distribution. The lack of any (mainstream) templating engine might hinder newcomers, and Flask uses one of the best python templating engines around. I also find Flask's documentation to be more extensive and better laid out. Overall I would recommend Flask if you want to write a full featured website, Bott…

You can use Jinja2 with Bottle:

> pip install Jinja2

from bottle import jinja2_template as template

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

#75

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.)

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

#76
post #66
post #65

Earlier quoted context omitted.

That's a fair bit more involved than "FTP files to my web host and they usually just work"

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

As a Mercurial user who doesn't feel like learning git just for the sake of deploying toy Python apps, can anyone comment on whether hg-git or the like is a reasonable way of deploying to heroku?

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

#77
post #49
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…

Python 3 is not "really that new" and Python 2.6-2.7 is not "old" in any way. In fact we have: pre-2.4 (really old, preinstalled on old Redhats), 2.4-2.7, 3.x Python 3 is curing problem with variable visibility (and if you do not write in "pure" functional way - you will never see this problem) and unicode strings. Other differences is not so "revolutionary".

> (and if you do not write in "pure" functional way - you will never see this problem)

Could you explain this a little more, please?

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

#79
post #41
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…

Python 2 versus 3 isn't anything like PHP 4 versus 5. The problem is that there are a few minor but backwards-incompatible changes to the syntax in py3. Libraries can't update until all their dependencies update. And web frameworks are some of the most complex software with the most dependencies, so they're updating last. It's still pretty much the same language behaving in the same way, though. If you know Python 2…

"Don't worry, migration from Python 2 to 3 is really easy. It'll take 5 minutes to learn."

"Migration for libraries from Python 2 to 3 is really hard. It's taken them a few years and counting."

??

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

#80
post #52
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…

CGI scripts have much of PHPs simplicity. You can just drop in a executable file, and depending bit on server configuration, it will just run. With Python a basic hello world would look something like this: #!/usr/bin/python print "Content-type: text/plain" print "" print "Hello World!" So 3 lines of "boilerplate", and then you can do anything you want. No extra packages to install or languages to learn. No framework…

And therein lies the problem, in WSGI

99% of web sites are hosted in "shared hosting" services

Now compare copying the .php files with configuring WSGI

"No, but WSGI is easy blah blah blah" it doesn't beat copying files And no, settings WSGI is not easy

Also, if you depend on IIS for example, PHP is almost plug'n'play

WSGI on Windows is the definition of "bag of hurt". You can try fastcgi to run on windows, and then you find out flup needs socket.fromfd

The easiest way, if it's your machine, run gunicorn or similar and just make Apache redirect the traffic.

But in shared services it's still way too complicated.

Post reply on HN