这是我的 django 项目层次结构
project/
apache/ django.wsgi
project/ __init__.py, settings.py, urls.py ..
pages/
__init__.py
widgets.py
website_views.py
services/
__init__.py
apis/
__init__.py
fparser.py
googleData.py
wp.py
...
wservice.py
...
因此,wservice.py
是一个类似于类的包装,位于 apis
模块的所有类之上。它甚至为它继承的所有类提供一些通用功能。
wservice.py
import feedparser
from bs4 import BeautifulSoup
class WidgetService(FParser):
def post_content_summary(self, post_number):
....
content_text = content_soup.get_text()
...
def get_random_image(self, post_number):
...
content_soup = BeautifulSoup(html_content)
...
FParser
类位于 fparser.py
fparser.py
中的方法以这种方式使用上面的类。
from services.wservice import WidgetService
def method1():
obj = WidgetService()
m1 = obj.foo1() # described in FParser class
m2 = obj.foo2() # described in WidgetService class
我在pages/widgets.py
中使用这个WidgetService()。所以,我发现,当我开始使用 BeautifulSoup
时,apache 服务器不会加载。它甚至没有显示任何语法错误。
我什至在日志文件中没有看到任何错误。
可能出了什么问题???有趣的是,我在开发服务器heroku(gunicorn)中没有遇到过这种错误
最佳答案
这可能就是所描述的 Cython 和 mod_wsgi 之间的交互 here ,并在 Beautiful Soup 上下文中进行探索 here 。这是an earlier question和你的类似。
关于python - 在类中加载外部模块时无法加载 apache 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11398911/