简体   繁体   中英

I'm confused about python web application

我刚刚学习了“python”编程以及有关 css 和 html 以及 java 脚本的基本知识,我之前是“php”程序员,我很困惑,是否可以仅在 python(服务器端)中编写 Web 应用程序使用框架(django、flask 等)或者如果我使用 django 开发,是否可以将它们(django 和 pyhotn)放在一个程序中

Django is built using Python therefore you'd not be able to build your Django web application without Python.

I suggest you to begin with the Django Getting Started checklist to see if it is something that you're looking for.

If you mean, you want to serve a web application and do something else in the very same process, sure. Start a thread and make your second thing-to-do a background thread. I'd consider it as a bad practice though. But you can try.

Otherwise, Django is Python.

And yes, theoretically, you can write a web application without Django or any framework. But you would need to write huge amounts of code. I don't think you're asking the question in this way but, just for making it clear.

You can write a web application the way you're used to in PHP using Python by using the cgi module.

However, while cgi style web application is simple for one page application, this is considered very poor style in Python, it doesn't scale, it's somewhat weird and tedious (because it abuses stdin/stdout), and it's bad for performance (because it has to reload all modules every request). This style of writing application doesn't scale to larger, more complicated projects, although this is the only style that is really available in PHP, but it is partly the reason why most major PHP frameworks almost always advise you to write .htaccess rules that rewrites all request to a single file. The same problems plagues PHP, however in PHP, cgi style application is somewhat less painful because the language is optimised for this style of application, but it is also the reason why PHP have had to preload thousands of built in functions in the global namespace; as the language would be unbearable to use otherwise.

In Python, it's more common to use WSGI to talk to the webserver, but using WSGI is much more complicated than CGI, as WSGI is very low level and is primarily intended for framework developer rather than application developer, and that WSGI requires you to keep a persistent process running (this is in contrast to the new process for every request style of CGI). Most application developers are expected to instead use a web framework, as Python has a lot of frameworks suited for many different projects and sizes of applications.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM