mod_python.publisher 始终给出内容类型“text/plain”;
我刚刚用 apache 设置了 mod python,我试图让一个简单的脚本工作,但是当我加载页面时,它会将我的所有 html 发布为纯文本。 我认为这是 mod_python.publisher 的问题,我也设置了它的处理程序。 我搜索了它的源代码,找到了区分 'text/plain' 和 'text/html' 的行,并且它在我的脚本中搜索它输出的文件的最后一百个字符,所以我将其放入,然后还是不行。 我什至尝试注释掉一些代码,以便发布者将所有内容设置为“text/html”,但当我刷新页面时它仍然做了同样的事情。 也许我设置有问题。
这是我在 httpd.conf 中的配置
< 目录“C:/Program Files/Apache Software Foundation/Apache2.2/htdocs”>
SetHandler mod_python
PythonHandler mod_python.publisher
Python调试打开
< /目录>
I've just set up mod python with apache and I'm trying to get a simple script to work, but what happens is it publishes all my html as plain text when I load the page. I figured this is a problem with mod_python.publisher, The handler I set it too. I searched through the source of it and found the line where it differentiates between 'text/plain' and 'text/html' and it searches the last hundred characters of the file it's outputting for ' in my script, so I put it in, and then it still didn't work. I even tried commenting out some of the code so that publisher would set everything as 'text/html' but it still did the same thing when I refreshed the page. Maybe I've set up something wrong.
Heres my configuration in the httpd.conf
< Directory "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs">
SetHandler mod_python
PythonHandler mod_python.publisher
PythonDebug On
< /Directory >
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的配置看起来不错:我有一个工作 mod_python.publisher 脚本,其设置基本相同。
其他一些想法:
当您尝试编辑发布者源代码时,您是否重新启动了网络服务器? 它仅在服务器首次启动时加载 Python 库一次。
发布商的自动检测会查找结束 HTML 标记:。 是你加的吗? (我在您的问题中看不到它,但可能在您发布它时它被删除了。)
如果没有其他效果,您始终可以显式设置内容类型。 它的代码更多,但保证能够一致地工作。 将请求中的 content_type 字段设置为“text/html”。
例如,如果您的脚本现在看起来像这样:
它将变成:
Your configuration looks okay: I've got a working mod_python.publisher script with essentially the same settings.
A few other thoughts:
When you tried editing the publisher source code, did you restart your web server? It only loads Python libraries once, when the server is first started.
Publisher's autodetection looks for a closing HTML tag: </html>. Is that what you added? (I can't see it in your question, but possibly it just got stripped out when you posted it.)
If nothing else works, you can always set the content type explicitly. It's more code, but it's guaranteed to work consistently. Set the content_type field on your request to 'text/html'.
For example, if your script looks like this right now:
it would become: