1. AI新视界首页
  2. AI经验分享

django常见问题(一)

django常见问题,随手记

Q1:将Debug=false后,所有页面都打不开,全部显示server error 500,但是设置Debug=true又好了
可能报错:CommandError: You must set settings.ALLOWED_HOSTS if DEBUG is False.
解决方案:ALLOWED_HOSTS = [‘127.0.0.1‘, ‘localhost‘](如果是部署到公网,则填写对应域名或者子域名)

Q2:报错信息: ModelForm Creating a ModelForm without either the ‘fields‘ attribute or the ‘exclude‘ attribute is prohibited; form AuthorForm needs updating.
解决方案:

Q3:报错信息: CSRF token missing or incorrect
解决方法:A1:
Step 1: 在 templete 中, 为每个 POST form 的form标签内部增加一个 {% csrf_token %} tag.
Step 2: 在 view 中, 使用 django.template.RequestContext 而不是 Context.render_to_response, 默认使用 Context. 需要改成 RequestContext.

解决方法: A2 :

原创文章,作者:ifyoung,如若转载,请注明出处:https://www.drugfoodai.com/django-exception-1.html

发表评论

邮箱地址不会被公开。 必填项已用*标注