错误一
raise exceptions.ImproperlyConfigured('Middleware module "%s" does not define a "%s" class' % (mw_module, mw_classname))
django.core.exceptions.ImproperlyConfigured: Middleware module "django.middleware.csrf" does not define a "CsrfResponseMiddleware" class
解决:
修改settings.py文件
将MIDDLEWARE_CLASSES里的django.middleware.csrf.CsrfResponseMiddleware注释掉
错误二
'mysql' isn't an available database backend.
Try using django.db.backends.mysql instead.
Error was: No module named mysql.base
修改settings.py文件
'ENGINE': 'django.db.backends.mysql' 这句话取消注释
'ENGINE': 'mysql',
这句话注释掉
- 'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
- # 'ENGINE': 'mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
错误三
Forbidden (403)
CSRF verification failed. Request aborted.
Help
Reason given for failure:
CSRF token missing or incorrect.
In general, this can occur when there is a genuine Cross Site Request Forgery, or when Django's CSRF mechanism has not been used correctly. For POST forms, you need to ensure:
Your browser is accepting cookies.
The view function uses RequestContext for the template, instead of Context.
In the template, there is a {% csrf_token %} template tag inside each POST form that targets an internal URL.
If you are not using CsrfViewMiddleware, then you must use csrf_protect on any views that use the csrf_token template tag, as well as those that accept the POST data.
You're seeing the help section of this page because you have DEBUG = True in your Django settings file. Change that to False, and only the initial error message will be displayed.
You can customize this page using the CSRF_FAILURE_VIEW setting.
解决:
方法一:(无效)
网上说在settings.py文件的MIDDLEWARE_CLASSES里增加django.middleware.csrf.CsrfResponseMiddleware,但是这和就会造成错误一,而且django1.4版本已经把这个模块去掉了。所以此方法不行。
方法二:(可行)
步骤1、修改from表单,在里面添加{% csrf_token %}
重启
uwsgi
,
uwsgi
日志出现:
UserWarning: A {% csrf_token %} was used in a template, but the context did not provide the value. This is usually caused by not using RequestContext.
warnings.warn("A {% csrf_token %} was used in a template, but the context did not provide the value. This is usually caused by not using RequestContext.")
网页报错还是
CSRF verification failed. Request aborted.
解决办法
步骤
2
修改
view.py
文件
在
return render_to_response
函数里加入
context_instance=RequestContext(request)
原来是
return render_to_response('login.xhtml', {"message" : u"
请先登录!!
"})
修改后:
return render_to_response('login.xhtml', {"message" : u"
请先登录!!
"},context_instance=RequestContext(request))
这样之后还是会报错
global name 'RequestContext' is not defined
步骤三:
修改
iew.py
,加上这句
RequestContext
原来
from django.shortcuts import render_to_response
修改后
from django.shortcuts import render_to_response,RequestContext
这样就
OK
啦