urllib2.urlopen fails in Django

人走茶凉 提交于 2020-01-02 12:47:13

问题


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.

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.

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


回答1:


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.



来源:https://stackoverflow.com/questions/10636608/urllib2-urlopen-fails-in-django

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!