开发者

"Vanilla" web python

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 reall开发者_Python百科y liking it.


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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜