urlib2.urlopen在Django失败 [英] urllib2.urlopen fails in Django

查看:124
本文介绍了urlib2.urlopen在Django失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 urllib2.urlopen(url)获取HTML内容。网址为 http://127.0.0.1:8000/m.html/
此方法成功获取HTML内容。

I use urllib2.urlopen(url) to get HTML content. The URL is http://127.0.0.1:8000/m.html/. This method succeeds in getting the HTML content.

但是在Django中,如果我尝试获取HTML内容,它将停止在函数中:

But in Django, if I try to get the HTML content, it stops in the function:

urllib2.urlopen('http://127.0.0.1:8000/m.html/').

它只是停止。它不报告错误,服务器也停止。

It just stops. It does not report an error and the server also stops.

我不知道为什么它在单个文件中工作,但在Django中有问题。

I don't know why it works in a single file, but has problems in Django.

推荐答案

Django开发服务器是单线程的。它不能同时提供请求单独的页面的视图,以及单独的页面本身。

The Django development server is single-threaded. It can't both serve the view that's requesting the separate page, and the seperate page itself.

但是,我不知道为什么要这样做 - 如果您想从应用程序中获取一些内容,只需调用视图代码本身。

However, I've no idea why you would want to do this anyway - if you want some content from within your application, just call the view code itself.

这篇关于urlib2.urlopen在Django失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆