tags:

views:

83

answers:

3

I was reading on web2py framework for a hobby project of mine I am doing. I learned how to program in Python when I was younger so I do have a grasp on it. Right now I am more of a PHP dev but kindda loathe it.

I just have this doubt that pops in: Is there a way to use "Vanilla" python on the backend? I mean Vanilla like PHP, without a Framework. How does templating work in that way? I mean, with indentation and Everything it kinda misses the point.

Anyway I am trying web2py and really liking it.

+2  A: 

There is no reason to do that :) but if you insist you can write on top of WSGI

I suggest that you can try a micro-framework such as web.py if u like it Vanilla style

PanosJee
Great Thanks. Not really wanting to, but was just really curious about it. There will be times when something I need to write is so small that using a framework would be overkill. I thought that perhaps python would be up for the job, but I guess that for small nimial things PHP would be a better fit.
actionAxolot
"so small that using a framework would be overkill": Cannot exist. Try it. You wind up writing so much code that duplicates framework features. Look at werkzeug for a framework that comes in smaller pieces. Don't ever claim that a web app is "too small" for a framework -- web apps are hard.
S.Lott
Didn't mean webapps. It was more on the likes of "small script to load an SQL dump when you only have ftp access". Those are like 5 lines o code. If there were a shell, I know Python would do just fine, otherwise PHP. Anyways the good side of not using shared hosting anymore is that theses scenarios will be non-existant.
actionAxolot
+1  A: 

without a framework, you use WSGI. to do this, you write a function application like so:

def application(environment, start_response):
    start_response("200 OK", [('Content-Type', 'text/plain')])
    return "hello world"

environment contains cgi variables and other stuff. Normally what happens is application will call other functions with the same call signature and you get a chain of functions each of which handles a particular aspect of processing the request.

You are of course responsible for handling your own templates. Nothing about it is built into the language.

aaronasterling
Yeah. That WSGI thing really changed my whole perspective. After checking it out I knew right away how this worked. Not how to do it, but found sense in it.
actionAxolot
+1  A: 

The mixing of logic, content, and presentation as naïvely encouraged by PHP is an abomination. It is the polar opposite of good design practice, and should not be imported to other languages (it shouldn't even be used in PHP, and thankfully the PHP world in general is ever so slowly moving away from it).

You should learn about Model-View-Controller (MVC) which, while not the final word on good real-world design, forms an important basis for modern web development practices, and serves as common ground, or a sort of lingua franca, in discussions about application layout.

Most of the time, you should be using some form of web framework, particularly one that provides templating. web2py is not a bad choice. Other popular frameworks include Pylons and Django.

Most Python web frameworks are very modular. You can use them in their entirety for everything in your app, or just bits and pieces. You might, for example, use Django's URL dispatcher, but not its models/ORM, or maybe you use everything in it except its templating engine, pulling in, say, Jinja. It's up to you.

You can even write traditional CGI scripts (take a look at the CGI module), while still using a templating engine of your choice.

You should start learning about all of these things and finding what works best for you. But the one thing you should not do is try to treat Python web development like PHP.

Nicholas Knight
Yeah. I think what you mention about not bringing old practices into new development environments is quite important. Otherwise I am not really learning everything. I hate programming 'Vanilla' PHP, just had this doubt. In fact in PHP I do most of my work with Yii framework, which I thought was the best rounded one. It separates this completely and with a couple of widgets developed per project I can just delegate all of the design to someone who actually knows what they are doing. Awesome reply. Thanks.
actionAxolot