1、django.core.exceptions.ImproperlyConfigured: WSGI application ‘LARS.wsgi.application’ could not be loaded; Error importing module.
设置SESSION_ENGINE时出错,(sessions写成session)
SESSION_ENGINE = "django.contrib.sessions.backends.cache"
2、KeyError: ‘BACKEND’
设置缓存系统时,CACHES的default键的BACKEND键写错了
3、 File “E:\CodingAndDocument\Python\GitForDjango\DRFLearning\lib\site-packages\django\contrib\sessions\middleware.py”, line 15, in init
engine = import_module(settings.SESSION_ENGINE)
File “E:\CodingAndDocument\Python\GitForDjango\DRFLearning\lib\importlib_init_.py”, line 118, in import_module
if name.startswith(’.’):
AttributeError: ‘tuple’ object has no attribute ‘startswith’
1.engine = import_module(settings.SESSION_ENGINE):表明出错的是SESSION_ENGINE配置错误,
2.AttributeError: 'tuple' object has no attribute 'startswith':表明是配置SESSION_ENGINE的值时在后面添加了一个逗号,比如
SESSION_ENGINE = "django.contrib.sessions.backends.cache", #后面不能加逗号,加了会被认为是元组类型
4、django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
原因:在pycharm的Python Console导入了django中的models
解决办法:应该在pycharm的Terminal中用命令行:python manage.py shell启动shell命令窗口
5、’"%s" is not a valid regular expression: %s’ % (regex, e)
django.core.exceptions.ImproperlyConfigured: “^snippets.(?P[a-z0-9]+)/?.(?P[a-z0-9]+)/?$” is not a valid regular expression: redefi
nition of group name ‘format’ as group 2; was group 1 at position 40
解决办法:删去urlpatterns = format_suffix_patterns(urlpatterns)
6、django.urls.exceptions.NoReverseMatch: Reverse for ‘app_list’ with keyword arguments ‘{‘app_label’: ‘auth’}’ not found. 1 pattern(s) tried: [‘admin/$
(?P<app_label>auth|myblog)/$’]
#原因:django的APP未加命名空间
在app的urls.py中加上:app_name = '你的app名称'
7、Method Not Allowed: /archive/ #报405错误
原因:编写views.py时,视图类中的get方法写成了post方法,导致方法不允许,所以报错
8、‘The model %s is already registered’ % model.name) xadmin.sites.AlreadyRegistered: The model Us
python manage.py makemigrations
python manage.py migrate
9、if cls.USERNAME_FIELD in cls.REQUIRED_FIELDS:
AttributeError: type object ‘UserProfile’ has no attribute ‘USERNAME_FIELD’
自定义用户模型时,用AbstractUser而不是AbstractBaseUser
10、django.db.utils.InternalError: (1050, “Table ‘tb_content’ already exists”)
python manage.py migrate --fake