django: failing tests from django.contrib.auth

大憨熊 提交于 2019-12-05 08:32:36

I have managed to reproduce the test results you are seeing by doing the following:

MIDDLEWARE_CLASSES = (
    'django.middleware.cache.UpdateCacheMiddleware',
    .... <your middleware classes> ....
    'django.middleware.cache.FetchFromCacheMiddleware',
)

If you have these lines, try removing them and re-running the unit test. I do not however have a solution for this.

Looks like you haven't got the 'user' key available in your context, or even no context at all...

In your settings.py do you have the following?

TEMPLATE_CONTEXT_PROCESSORS = (
    "django.core.context_processors.auth",
    "django.core.context_processors.debug",
    "django.core.context_processors.media",
    "django.core.context_processors.request",

     etc ....
)

Indeed, do you have TEMPLATE_CONTEXT_PROCESSORS at all? IIRC django-admin.py startproject doesn't actually include these in the default settings.py

Hope that helps

Steve

If you have Python 2.6.5, you need this patch: http://code.djangoproject.com/changeset/11821 .

Otherwise, did you import django.contrib.admin? There are certain templates that need to exist for django.contrib.auth 's tests (your code shouldn't be affected if they are not there) to work, and django.contrib.admin happens to provide them.

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