save() prohibited to prevent data loss due to unsaved related object ‘hbook’.
这是因为在创建的时候,必须先保存你要生成外键的另一个表的数据,
比如,图书表和英雄表,他们是一对多的关系,创建一个外键在,英雄表中,这个时候,必须先保存图书表中的数据,英雄表才可以保存
2’test’ is not a registered tag library. Must be one of: admin_list admin_modify admin_urls cache i18n l10n log static tz
为了使 {% load %} 标签生效,包含自定义标签的应用必须包含在 INSTALLED_APPS 中。这是个安全特性:它允许你在一个主机上持有多个模板库,而不是让每个 Django 安装都能访问所有的库。
3、django.template.exceptions.TemplateSyntaxError: ‘staticfiles’ is not a registered tag library. Must be one of:
遇到这个问题,如果你所有的没有问题,路径,单词书写等都没有问题的话,重启开发软件,重启服务器即可。[color=rgba(0, 0, 0, 0.75)]
4、TypeError: BlockIPSMiddleware() takes no arguments
因为django3改了所以需要再写中间件类的时候需要加一个父类
[Python] 纯文本查看复制代码?
12345678 | from django.http import HttpResponse from django.utils.deprecation import MiddlewareMixin class BlockIPSMiddleware(MiddlewareMixin): IP_LIST = [ '192.168.42.129' def process_view( self ,request, view_func, * view_args, * * view_kwargs): user_ip = request.META[ 'REMOTE_ADDR' if user_ip in BlockIPSMiddleware.IP_LIST: return HttpResponse( "IP已经被封" ) |