Using python to develop web application

前端 未结 9 782
小鲜肉
小鲜肉 2021-01-30 07:38

I have been doing some work in python, but that was all for stand alone applications. I\'m curious to know whether any offshoot of python supports web development?

Would

相关标签:
9条回答
  • 2021-01-30 08:23

    Edited 3 years later: Don't use mod_python, use mod_wsgi. Flask and Werkzeug are good frameworks too. Needing to know what's going on is useful, but it isn't a requirement. That would be stupid.

    Don't lookup Django until you have a good grasp of what Django is doing on your behalf. for you. Write some basic apps using mod_python and it's request object. I just started learning Python for web-development using mod_python and it has been great.

    mod_python also uses a dispatcher in site-packages/mod_python/publisher.py. Have a ganders through this to see how requests can be handled in a simple-ish way.

    You may need to add a bit of config to your Apache config file to get mod_python up and running but the mod_python site explains it well.

    <Directory /path/to/python/files>
         AddHandler mod_python .py
         PythonHandler mod_python.publisher
         PythonDebug On
    </Directory>
    

    And you are away!

    use (as a stupidly basic example):

    def foo(req):
        req.write("Hello World")
    

    in /path/to/python/files/bar.py assuming /path/to is your site root.

    And then you can do

    http://www.mysite.com/python/files/bar/foo
    

    to see "Hello World". Also, something that tripped me up is the dispatcher uses a lame method to work out the content-type, so to force HTML use:

    req.content_type = 'text/html'
    

    Good Luck

    After you have a good idea of how Python interacts with mod_python and Apache, then use a framework that does all the boring stuff for you. Up to you though, just my recommendation

    0 讨论(0)
  • 2021-01-30 08:25

    Lookup Django.

    0 讨论(0)
  • 2021-01-30 08:26

    Python Wiki: Web Frameworks for Python

    If you decide to use Django, the official tutorial is an excellent place to start. The Django Book is also free.

    0 讨论(0)
提交回复
热议问题