我似乎无法在我的Django应用程序中将数据库模型导入中间件。
我所拥有的是一个名为用户跟踪的应用程序,位于
中 user_tracking/middleware/user_tracking.py
看起来像这样:
from django.db import model
from user_tracking.models import SourceID
class UserSessionTracking(object):
def process_request(self, request):
## Stuff that comes from the page meta
auth_user = None
try:
auth_user = request.META['REMOTE_USER']
except KeyError:
auth_user = "None"
我这里也有一个models.py:
user_tracking/models.py
内容:
import datetime
from django.db import models
from django.utils import timezone
class SourceID(models.Model):
source_name = models.CharField(max_length=60)
http_ref = models.CharField(max_length=80)
def __str__(self):
return self.source_name
现在我在每个页面加载时都会收到以下错误消息:
Traceback (most recent call last):
File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
self.result = application(self.environ, self.start_response)
File "/usr/lib/python2.7/dist-packages/django/contrib/staticfiles/handlers.py", line 64, in __call__
return self.application(environ, start_response)
File "/usr/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 168, in __call__
self.load_middleware()
File "/usr/lib/python2.7/dist-packages/django/core/handlers/base.py", line 44, in load_middleware
mw_class = import_string(middleware_path)
File "/usr/lib/python2.7/dist-packages/django/utils/module_loading.py", line 26, in import_string
module = import_module(module_path)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/dengar/Documents/development/neshitje/neshitje/user_tracking/middleware/track.py", line 2, in <module>
from user_tracking.models import SourceID
ImportError: No module named models
[05/Sep/2015 18:12:14] "GET / HTTP/1.1" 500 59