1.mysqlclient 目前不支持高版本python3
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.
原因是由於 mysqlclient 目前不支持高版本python,出現這個錯誤之后可以根據錯誤提示找到文件位置,打開 base.py 文件,找到以下代碼:將 if 語句注釋掉之后在執行命令就不會再報錯。
1.Watching for file changes with StatReloader(使用狀態加載程序監視文件更改
原因:可能是Django版本和Python版本或者PyMysql版本不一致
解決辦法:https://www.jianshu.com/p/c44b0c88fafe
原因:跟路由沒修改,我這里出的錯是crm/urls.py中url(r'^$', views.dashboard ),--把$去掉就好了。
解決https://www.cnblogs.com/guokaifeng/p/11084997.html
3.Django 中創建Model時報以下錯誤:
TypeError: init() missing 1 required positional argument: ‘on_delete’
解決方案: 定義外鍵的時候需要加上 on_delete=; 即:contract = models.ForeignKey(Contract, on_delete=models.CASCADE)
原因如下: django 升級到2.0之后,表與表之間關聯的時候,必須要寫on_delete參數,否則會報異常:
4.添加menus菜單時報錯:
Exception Value: no such table: crm_menus
解決:python manage.py makemigrations crm
python manage.py migrate
5.Django報錯Exception Value: no such table xx
執行以下兩步驟: python manage.py makemigrations app_name python manage.py migrate
6.django數據遷移時報錯;TypeError: object supporting the buffer API required
解決:settings.py中密碼必須為字符串類型
7.pycharm 換成2019之后連接數據庫用戶名密碼數據庫名字都沒錯,就是連接不上去:
Connection to nb_crm@localhost failed. [08001] Could not create connection to database server. Attem
解決辦法:
在終端里先使用管理員登錄mysql,也就是root
解決:執行如下命令更改時區:
show variables like '%time_zone%'; set global time_zone = '+8:00' ; 設置完以后,退出mysql,重新登錄,檢查時間是否被修改,結束后就退出cmd,去pycharm里面重新連接看看
8.FieldError at /crm/consult_record_list/
Cannot resolve keyword 'delete_status' into field. Choices are: course_memo, course_title, date, day_num, has_homework, homework_memo, homework_title, id, re_class, re_class_id, scoring_point, studyrecord, teacher, teacher_id
9.報錯:django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.
解決:原因是由於 mysqlclient 目前不支持高版本python,出現這個錯誤之后可以根據錯誤提示找到文件位置,打開 base.py 文件,找到以下代碼:將 if version 語句注釋掉之后在執行命令就不會再報錯。
version = Database.version_info # if version < (1, 3, 13): # raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)
10.啟動django時報錯Watching for file changes with StatReloader(使用狀態加載程序監視文件更改 )
INFO autoreload 598 Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/root/.virtualenvs/meiduo_mall/lib/python3.6/site-packages/django/template/utils.py", line 66, in __getitem__
return self._engines[alias]
KeyError: 'django'
............
return [self[alias] for alias in self]
File "/root/.virtualenvs/meiduo_mall/lib/python3.6/site-packages/django/template/utils.py", line 90, in <listcomp>
return [self[alias] for alias in self]
File "/root/.virtualenvs/meiduo_mall/lib/python3.6/site-packages/django/template/utils.py", line 81, in __getitem__
engine = engine_cls(params)
File "/root/.virtualenvs/meiduo_mall/lib/python3.6/site-packages/django/template/backends/django.py", line 27, in __init__
self.engine = Engine(self.dirs, self.app_dirs, **options)
TypeError: __init__() got an unexpected keyword argument 'environment'
原因:可能是Django版本和Python版本或者PyMysql版本不一致
解決:升級或者降級Django版本
如:命令如下:
pip install django==2.1.7 #django==版本號
10.啟動項目報錯:-----更換jinja2模板引擎的問題
ERRORS: ?: (admin.E403) A 'django.template.backends.django.DjangoTemplates'
解決:
解決辦法: 不修改原有引擎配置,新增引擎jinja2, 即在settings.py中 TEMPLATES = [ { 'BACKEND': 'django.template.backends.jinja2.Jinja2', 'DIRS': [os.path.join(BASE_DIR,'templates'),], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], 'environment':'app.base_jinja2.environment' }, }, { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.path.join(BASE_DIR, 'templates')] , 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, } ] 並且一定要把jinja2 引擎放在前面, 否則默認生效的還是django模板引擎
11.圖形驗證碼出不來,看下圖效果:
從上圖中可看出請求頭中有meiduo.site又是127.0.0.0這樣肯定出不來---因為我是在本地127請求,所以先去找我js中的host代碼,把host代碼改成127如下即可: