在 chrome 中呈现在正文中的元标记 (django)

meta tag rendered in body in chrome (django)

我在 django 应用程序中的 html 模板如下所示:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <title>sth</title>


    <!-- Bootstrap -->
    <link href="static/css/bootstrap.min.css" rel="stylesheet" type="text/css" />

</head>
<body id="page-top" class="index" data-spy="scroll" data-offset="0">

    <!-- Navigation -->
    <nav class="navbar navbar-default navbar-fixed-top">
        <div class="container">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header page-scroll">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#my-navbar">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand page-scroll" href="#page-top">STH</a>
            </div>

            <div class="collapse navbar-collapse" id="my-navbar">

                <ul class="nav navbar-nav">
                    <li class="hidden">
                        <a href="#page-top"></a>
                    </li>
                    <li><a class="page-scroll" href="#a1">a1</a></li>
                    <li><a class="page-scroll" href="#a2">a2</a></li>
                    <li><a class="page-scroll" href="#a3">a3</a></li>
                    <li><a class="page-scroll" href="#a4">a4</a></li>
                </ul>

                <ul class="nav navbar-nav navbar-right">
                    <li><a href="/logout/">Logout</a></li>
                </ul>

            </div>
        </div>
    </nav>

    <!-- Header -->
    <header>
        <div class="container">
            <div class="intro-text">
                <div class="intro-heading">Heading!</div>
            </div>
        </div>
    </header>


    <!-- Content to extend -->

    <section id="a1">
        <div class="container">
            Lots of Text
        </div>
    </section>

    <section id="a2">
        <div class="container">
            Lots of Text ...
        </div>
    </section>

    <section id="a3">
        <div class="container">
            Lots of Text ...
        </div>
    </section>

    <section id="a4">
        <div class="container">
            Lots of Text ...
        </div>
    </section>

    <!-- Footer -->
    <footer>
        <div class="container">
            <h4>

                Footer

            </h4>
        </div>
    </footer>



    <!-- jQuery -->
    <script src="/static/js/jquery.js"></script>
    <!-- Bootstrap Core JavaScript -->
    <script src="/static/js/bootstrap.min.js"></script>

    <!-- Plugin JavaScript -->
    <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js"></script>
    <script src="/static/js/classie.js"></script>
    <script src="/static/js/cbpAnimatedHeader.js"></script>

    <script src="/static/parsley/parsley.js"></script>
</body>
</html>

并且在 firefox 中一切正常

而在 chrome 中,此 html 呈现如下:

<html lang="en">
#shadow-root
<shadow></shadow>
<style type="text/css"></style>
<head></head>
<body>
"



"
      <meta charset="utf-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <meta name="description" content="">
      <meta name="author" content="m">
      <title>Sth</title>

      <!-- Bootstrap -->
     <link href="/static/css/bootstrap.min.css" rel="stylesheet" type="text/css" >
     ...

所以 meta 和其他 css 在 body 元素内。我认为是因为 bootstrap 中的一些东西不能正常工作(例如 dataspy)。 (当我使用 "Sources" 选项卡在 chrom dev 工具中检查我的文件的 html 时,一切似乎都正常”,但在 "Elements" 选项卡中,它显示得很奇怪,如上所示。

正如我提到的,我正在使用 Django 和 Bootstrap

关闭页眉并添加正文标签

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="m">
<title>Sth</title>

{% load staticfiles %}
<!-- Bootstrap -->
<link href="{% static 'css/bootstrap.min.css' %}" rel="stylesheet" type="text/css" />
</head>
<body>
...
</body>

问题出在编码上。我在 IDE 中将默认保存设置设置为 "UTF8 with signature",但应该是 "UTF8 without signature"。

希望对大家有所帮助。