Django - 覆盖 base_site.html 后,我无法发布我的 post 并导致 CSRF 错误
Django - After overriding the base_site.html, i was unable to publish my post and causing CSRF error
这是我的 base_site.html
代码
{% extends "admin/base.html" %}
{% load static %}
{% block title %}{% if subtitle %}{{ subtitle }} | {% endif %}{{ title }} |
{{ site_title|default:_('Admin') }}
{% endblock %}
{% block extrastyle %}
<style type="text/css">
#branding h1{
color: #fff !important;
}
#branding h1 a:link, #branding h1 a:visited {
color: #fff !important;
}
.submit-row input{
background-color: #00b388;
}
#header {
background-color: #000000;
color: #fff !important;
}
.module caption{
background-color: #00b388;
}
div.breadcrumbs {
background: #00b388;
}
.object-tools a.addlink{
background-color: #00b388;
}
input[type=submit].default, .submit-row input.default{
background-color: #00b388;
}
</style>
{% endblock %}
{% block branding %}
<form method="post">{% csrf_token %}
<h1 id="site-name"><a href="{% url 'admin:index' %}"><img src="{% static 'img/logo.PNG' %}" height="30px" /></a></h1>
{% endblock %}
{% block nav-global %}
{% endblock %}
unfortunately i have added the <form> tag in the above code, just to over come with CSRF issue and it does.
unfortunately, this approach gives me another error,
即,我的模型中有 3 个文件字段,尽管我在上传过程中提到了这些文件,但当我点击提交时,它不起作用并一直显示此字段为必填错误。
I am new to Django and your response helps me great.
versions:-
Django - 2.2
python - 3.6.2
您需要关闭表单标签:
<form method="post">{% csrf_token %}
</form>
<h1 id="site-name"><a href="{% url 'admin:index' %}"><img src="{% static 'img/logo.PNG' %}" height="30px" /></a></h1>
{% endblock %}
{% block nav-global %}
{% endblock %}
这是我的 base_site.html
代码{% extends "admin/base.html" %}
{% load static %}
{% block title %}{% if subtitle %}{{ subtitle }} | {% endif %}{{ title }} |
{{ site_title|default:_('Admin') }}
{% endblock %}
{% block extrastyle %}
<style type="text/css">
#branding h1{
color: #fff !important;
}
#branding h1 a:link, #branding h1 a:visited {
color: #fff !important;
}
.submit-row input{
background-color: #00b388;
}
#header {
background-color: #000000;
color: #fff !important;
}
.module caption{
background-color: #00b388;
}
div.breadcrumbs {
background: #00b388;
}
.object-tools a.addlink{
background-color: #00b388;
}
input[type=submit].default, .submit-row input.default{
background-color: #00b388;
}
</style>
{% endblock %}
{% block branding %}
<form method="post">{% csrf_token %}
<h1 id="site-name"><a href="{% url 'admin:index' %}"><img src="{% static 'img/logo.PNG' %}" height="30px" /></a></h1>
{% endblock %}
{% block nav-global %}
{% endblock %}
unfortunately i have added the <form> tag in the above code, just to over come with CSRF issue and it does.
unfortunately, this approach gives me another error,
即,我的模型中有 3 个文件字段,尽管我在上传过程中提到了这些文件,但当我点击提交时,它不起作用并一直显示此字段为必填错误。
I am new to Django and your response helps me great.
versions:-
Django - 2.2
python - 3.6.2
您需要关闭表单标签:
<form method="post">{% csrf_token %}
</form>
<h1 id="site-name"><a href="{% url 'admin:index' %}"><img src="{% static 'img/logo.PNG' %}" height="30px" /></a></h1>
{% endblock %}
{% block nav-global %}
{% endblock %}