1. django.utils.InternalError:(1049,"Unknown database 'community'")
在使用mysql数据库前得先创建数据库
-
$mysql -u root -p
-
>create database 数据库名字;
2.django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.Did you install mysqlclient?
订:
$pip3 install mysqlclient
如果还是出现这个是因为 Django 在连接 MySQL 数据库时默认使用的是 MySQLdb 驱动,然而我们没有安装该驱动,因为它并不支持 Python3,我们现在安装的是 PyMySQL 驱动:
$pip install pymysql
然后在django项目的__init__下设置:
然后cmd执行
$ Python3 manage.py makemigations
$Python3 manage.py migrate
因为切换了数据库后,之前 Sqlite3 数据库里的数据并不能复制到 MySQL 中,所以需要重新进行数据库同步,使数据模型重新在 MySQL 数据库中生成表。
3. File "/Users/terese/Desktop/Community/home/urls.py", line 8, in <module>
path('', home.home, name='home'),AttributeError: 'function' object has no attribute 'home'
4. NoReverseMatch at /signup/
Reverse for 'home' not found. 'home' is not a valid view function or pattern name.
5. TypeError: index() missing 1 required positional argument: 'request'
原因:
path('’,views.index(),name='index'),用了.index()
订正:
改为views.index就好了
6.TemplateDoesNotExist at /
原因:
因为settings 没有被告诉template文件夹的位置
订正:
加上 'DIRS': [os.path.join(BASE_DIR, 'templates')],
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
…...
}
7.''static'' is not a registered tag library. Must be one of: admin_list admin_modify admin_static admin_urls cache i18n l10n log static staticfiles tz
django.template.exceptions.TemplateSyntaxError: ''static'' is not a registered tag library. Must be one of:
admin_list
admin_modify
admin_static
admin_urls
cache
i18n
l10n
log
static
staticfiles
原因:没有成功载入static,因为把static写成了’static’
订正:{% load static %}
8. django.urls.exceptions.NoReverseMatch: Reverse for 'add_book/' not found. 'add_book/' is not a valid view function or pattern name.
原因:没有add_book/这个url的名字,所以找不到,应该是add_book
path('add_book/',views.add_book,name='add_book’)#此处定义为add_book为URL名称
<li><a href="{% url 'add_book/' %}">发布图书</a></li>
订正为:
<li><a href="{% url 'add_book' %}">发布图书</a></li>
-
django.template.exceptions.TemplateSyntaxError: Invalid block tag on line 21: 'endblock'. Did you forget to register or load this tag?
原因:注意到没有,下面第一个{与%间有空格
{ % block content %}
订正:
{% block content %}
9."GET /static/home/home.css HTTP/1.1" 404 1663不能载入到网页
原因:检查一下home.css保存的位置是不是在 /static/home/home.css,发现在文件夹home的外面,
订正:
把文件拉到正确的位置