开发者

Python CGI without HTML clutter in source code?

I am new to web development. After much consideration I picked Python over Ruby simply because code readability is 开发者_开发知识库important to me. I have looked at a few Python cgi code and I wondered if it is possible to polish that code in such a manner that I can focus on program functionality without having to have all the HTML formatting code embedded (cluttering) in the Python source, i.e. separate the actual Python code from the HTML code. Perhaps this style of programming then leaves the realm of CGI into something else? (i.e. CGI = script that generates a web page).


Pick a template engine. And it's still CGI, it just happens to be CGI that uses a template engine; CGI is the interface, not the programming methodology.


is possible to polish that code in such a manner that I can focus on program functionality without having to have all the HTML formatting code embedded (cluttering) in the Python source

Use a templating engine

Perhaps this style of programming then leaves the realm of CGI into something else?

CGI isn't a style of programming. It is a means for a web server to execute a program to determine what data to provide to the user. (It is a slow and inefficient method, but it is also a very simple one).

If you want to get away from CGI and stay with Python, then you should probably look towards wsgi


New web application code in Python isn't written using CGI, it's based on WSGI. Separating your HTML generation from the rest of your program logic is indeed a good thing, and should be done using a templating engine. Python also has several frameworks for writing web applications; if you're just starting out, I recommend Flask.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜