我在这里有一个小测试场景,因为我的主项目有一个奇怪的错误。它从body标签中的标签渲染我的内容,我无法发现问题所在。
layout.html
{% load static %}
<!DOCTYPE html>
<html>
<head>
<!--Test-->
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="/" class="navbar-brand">Application name</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="{% url 'home' %}">Home</a></li>
<li><a href="{% url 'about' %}">About</a></li>
<li><a href="{% url 'contact' %}">Contact</a></li>
</ul>
{% include 'app/loginpartial.html' %}
</div>
</div>
</div>
<div class="container body-content">
{% block content %}{% endblock %}
<hr/>
<footer>
<p>© {{ year }} - My Django Application</p>
</footer>
</div>
<script src="{% static 'app/scripts/jquery-1.10.2.js' %}"></script>
<script src="{% static 'app/scripts/bootstrap.js' %}"></script>
<script src="{% static 'app/scripts/respond.js' %}"></script>
{% block scripts %}{% endblock %}
</body>
</html>
index.html
{% extends "backend/layout.html" %}
{% block content %}Test{% endblock %}
输出:
<html><head></head><body style="">
<!--Test-->
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="/" class="navbar-brand">Application name</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="/">Home</a></li>
<li><a href="/about/">About</a></li>
<li><a href="/contact/">Contact</a></li>
</ul>
<form id="logoutForm" action="/logout/" method="post" class="navbar-right">
<input type="hidden" name="csrfmiddlewaretoken" value="pVxWYntPq9xRYYTxwvm44i9QHAooOClw4BwobLx9oVbtbpRSbNqPVnBZD20AKSIw">
<ul class="nav navbar-nav navbar-right">
<li><span class="navbar-brand">Hello westcoast-dk!</span></li>
<li><a href="javascript:document.getElementById('logoutForm').submit()">Log off</a></li>
</ul>
</form>
</div>
</div>
</div>
<div class="container body-content">
Test
<hr>
<footer>
<p>© 2019 - My Django Application</p>
</footer>
</div>
<script src="/static/app/scripts/jquery-1.10.2.js"></script>
<script src="/static/app/scripts/bootstrap.js"></script>
<script src="/static/app/scripts/respond.js"></script>
</body></html>
我错了什么?布局大部分是从示例文件复制的。同样,我所做的总是在这个奇怪的输出中呈现。
PS,我的意思是只是head标签中的文本而不是Body标签中的
致谢 克里斯托弗。
答案 0 :(得分:0)
这是Visual Studio 2019中的错误-我添加了高级保存选项并将其从UTF8更改为Unicode 1250,现在可以使用。
https://docs.microsoft.com/en-us/visualstudio/ide/encodings-and-line-breaks?view=vs-2019