测试因Django 1.9 env中的错误而失败,但测试在1.10.4和1.8中运行良好。有人可以在这里发光吗?
这是错误
ADD_MESSAGE 提出MessageFailure('你不能在没有安装&#39的情况下添加消息; MessageFailure:如果没有安装django.contrib.messages.middleware.MessageMiddleware
,则无法添加消息
检查https://travis-ci.org/invaana/Hydronium/builds/182190626是否有完整错误
views.py
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<img width="1" height="1">
tests.py
def contact(request):
if request.method == "POST":
form = ContactForm(request.POST)
if form.is_valid():
form.save()
messages.success(request, 'Operation Successful! This is demo. Im not sending any messages')
else:
form.errors
messages.error(request, 'Message not sent, Please fix the errors!.' )
else:
form = ContactForm()
return render(request, 'pages/contact.html', {'form': form})
答案 0 :(得分:0)
显然,
MIDDLEWARE_CLASSES用于1.9,1.8
MIDDLEWARE用于1.10.4。
为了使中间件兼容两者,我在settings.py
MIDDLEWARE = MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]