【问题标题】:meta tag rendered in body in chrome (django)在 chrome (django) 中呈现在正文中的元标记
【发布时间】:2015-03-03 08:29:56
【问题描述】:

我在 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 元素中。我认为因此引导程序中的某些内容无法正常工作(例如 dataspy)。 (当我使用“Sources”选项卡在 chrom 开发工具中检查我的文件的 html 时,一切似乎都正常”,但在“Elements”选项卡中它显示的如此奇怪,如上所示)。

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

【问题讨论】:

  • 您确定您正在正确关闭head 等吗?
  • 是的。我正在检查每个标签....
  • 我对此表示怀疑。无论如何,您可以使用模板的实际内容编辑问题(除非它是机密的..)?
  • 我在源代码上使用 w3 验证器。正如我所提到的,在 Firefox 中一切正常。我将删除机密部分并粘贴源代码

标签: django html twitter-bootstrap


【解决方案1】:

问题在于编码。我在我的 IDE 中将默认保存设置设置为“带签名的 UTF8”,但应该是“不带签名的 UTF8”。

我希望它会对某人有所帮助。

【讨论】:

    【解决方案2】:

    关闭头部并添加body标签

    <!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>
    

    【讨论】:

    • 我没有写下我的其余文件,但有所有需要的标签并正确结束。
    猜你喜欢
    • 2017-04-24
    • 2020-04-15
    • 2013-05-23
    • 1970-01-01
    • 2012-12-19
    • 2016-06-12
    • 1970-01-01
    • 1970-01-01
    • 2019-02-05
    相关资源
    最近更新 更多