Live data from Hacker News

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

me.veekun.com

51–60 of 196 posts

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

#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 frameworks necessary.

edit: just as an example of minimal hello world in WSGI:

    def application(environ, start_response):
        start_response('200 OK', [('Content-type', 'text/plain')])
        yield 'Hello World!'
also doesn't need any extra python packages or frameworks. but configuring web server to handle wsgi is bit more involved than cgi.

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

#54
post #48
post #36

Earlier quoted context omitted.

So, you are telling me that it is a good thing, a normal behavior for a reliable tool to just ignore instructions I send to it and do nothing with it, not even a warning? So when I migrate a database, I have to carefully check each and every instructions (schema and data) and make sure MySQL did not "decide" it was not worth it and just silently threw it by the window? I have hard time to believe you are serious here…

I'm pretty certain when you migrate from a different database you're supposed to check your schema and data anyway, or do you just "decide" it should work without question? I'm not saying this MySQL behavior is acceptable, I'm just saying that you should be aware of the limitations and quirks of the tools you work with.

So it's not acceptable behaviour, yet we shouldn't point it because we should know it has this unacceptable behaviour? Doesn't make any sense to me I'm afraid.

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

#55

I like java for web app development, simply because it has a well-structured api and a massive community of developers who have run in to the majority of the road blocks you will most likely encounter on the way to launching your app.

What frameworks and platforms would you recommend for web development with java? I am writing my senior project at college in java (mainly because of the wide amount of image processing libraries available) and would love to add web capabilities.

Wicket, a thousand times wicket. It's so good it makes programming in java worthwhile. Its templating, if you can even call it that, is a quantum leap ahead of everything else: it's actually object oriented, you can write self-contained reusable components in the way you expect, and you get the full benefits of strong typing at every point. I really wish there was something like it for python, but everyone seems to think templates are good enough.

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

#56
Good article apart from one thing - avoid the hell out of session state. This becomes the dumping ground for all sorts of crap and will slowly knacker your app. You should only persist enough information to identify the user between requests and keep the rest stateless. We do that using encrypted cookies containing the user id, display name and correlation id.

I've just spent 6 months entirely removing session state from an asp.net app and the performance gain is amazing.

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

#57
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, Bottle if you are looking to write some kind of API layer, or similarly bear bones functionality, and will not require many "batteries included".

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

#58
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…

For the vast majority of projects, upgrading (or working with both PY2 and PY3 at the same time) is not that big of a deal unless the project you're working on is really, really old (2.3 days). At work we run unittests targeting different python versions and the most time I've spent changing a typically 4k loc project's codebase to work on both 2 and 3 has been around 4 hours. The average around 1.

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

#59

I have no idea why web2py gotten such a bad rep. I am a beginning webdeveloper and seriously: web2py is a pleasure to work with. Simple to start, deploy, port and hack. It's backwards compatible and has a template language that really is non existant as so far as its pure python. Compare that to Rails - which is (comparable) hell to set-up and breaks with upgrades etc. If you want python web development to be simple,…

> But I don't think so. One of the reasons for this is that Jakob Moss removed his web2py bashing from this thread. Didn't edit - removed it: https://www.quora.com/Is-web2py-a-good-Python-web-framework/....

What did he remove?

https://www.quora.com/Is-web2py-a-good-Python-web-framework/...

This isn't the first instance of Django/Flask people not agreeing with web2py design and implementation, and they have been vocal about it a couple of times.

http://www.reddit.com/r/Python/comments/ex54j/seeking_clarif...

Look for comments by mitsuhiko(flask dev) and jacobian(django dev).

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

#60
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…

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.

Post reply on HN