문제

So far I've only ever had to enable django middleware that appears to already be installed on my system. This was done by adding the relevant line to my settings.py file.

Now, however, I'm trying to install 3rd party middleware, and having all kinds of trouble.

The package is django-mobi, and in following the instructions https://pypi.python.org/pypi/django-mobi/> I just keep getting an Error 200 in my browser when I run the apache restart script after altering the settings.py file.

Here's what I've done:

1) Placed the "package" in my project path, which googling suggests means anything below "myproject" directory:

$ ls
django-mobi-0.1.7  django-mobi-0.1.7.tar.gz  manage.py  mobi  myproject

2) Added the line specified to the settings.py file

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'mobi.MobileDetectionMiddleware',
)

Restarting apache without that last mobi line commented out of the tuple results in an Error 200, even though I've got debug mode on, so it's of no help in diagnosing the problem.

Thank you so much for your help.

도움이 되었습니까?

해결책

Finally got it. Based on the directory structure of what I untarred, there's an extra 'middleware' filename that needed to be added to the path in settings.py. So now it looks like this:

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'mobi.middleware.MobileDetectionMiddleware',
    )

And it works fine

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top