0

I seem to be unable to import a Database models into middleware in my Django app.

What I have is an app called user tracking that resides in

user_tracking/middleware/user_tracking.py

It looks like this:

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"

I also have a models.py here:

user_tracking/models.py

with the content:

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

Now I do get the following error message on each page load:

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
dengar81
  • 2,485
  • 3
  • 18
  • 23

0 Answers0