Writing a website in Python

2020-02-16 08:20发布

I'm pretty proficient in PHP, but want to try something new.

I'm also know a bit of Python, enough to do the basics of the basics, but haven't used in a web design type situation.

I've just written this, which works:

#!/usr/bin/python

def main():
    print "Content-type: text/html"
    print
    print "<html><head>"
    print "<title>Hello World from Python</title>"
    print "</head><body>"
    print "Hello World!"
    print "</body></html>"

if __name__ == "__main__":
    main()

Thing is, that this seems pretty cumbersome. Without using something huge like django, what's the best way to write scripts that can process get and post?

标签: python
9条回答
贼婆χ
2楼-- · 2020-02-16 08:35

I agree with Paolo - Django is pretty small and the way to go - but if you are not down with that I would add to TurboGears to the list

查看更多
唯我独甜
3楼-- · 2020-02-16 08:47

What is "huge" is a matter of taste, but Django is a "full stack" framework, that includes everything from an ORM, to templates to well, loads of things. So it's not small (although smaller than Grok and Zope3, other full-stack python web frameworks).

But there are also plenty of really small and minimalistic web frameworks, that do nothing than provide a framework for the web part. Many have been mentioned above. To the list I must add BFG and Bobo. Both utterly minimal, but still useful and flexible.

http://bfg.repoze.org/ http://bobo.digicool.com/

查看更多
beautiful°
4楼-- · 2020-02-16 08:50

If you are looking for a framework take a look at this list: Python Web Frameworks

If you need small script(-s) or one time job script, might be plain CGI module is going to be enough - CGI Scripts and cgi module itself.

I would recommend you to stick to some framework if you want to create something more then static pages and simple forms. Django is I believe most popular and most supported.

查看更多
登录 后发表回答