Django模板的内容在渲染后立即消失

时间:2016-09-16 13:37:33

标签: django django-templates

编辑:问题是由广告拦截器引起的

我正在尝试创建一个帐户详细信息页面,其中显示了Account-对象的一些属性。我有一个视图传递要在模板中呈现的对象。在Firefox中,渲染页面根本不显示属性,而在chrome中,您可以看到它们一秒钟后消失。我正在使用Django 1.7.1和Python 2.7。提前谢谢!

这是我的代码,它基于ASCII value of decimal 32课程资料:

views.py:

class Account(models.Model):
    uuid = ShortUUIDField(unique=True)
    name = models.CharField(max_length=80)
    desc = models.TextField(blank=True)
    address_one = models.CharField(max_length=100)
    address_two = models.CharField(max_length=100, blank=True)
    city = models.CharField(max_length=50)
    state = models.CharField(max_length=2)
    phone = models.CharField(max_length=20)
    owner = models.ForeignKey(User)
    created_on = models.DateField(auto_now_add=True)

    class Meta:
        verbose_name_plural = 'accounts'

    def __unicode__(self):
        return u"%s" % self.name

    @models.permalink
    def get_absolute_url(self):
        return 'account_detail', [self.uuid]

    @models.permalink
    def get_update_url(self):
        return 'account_update', [self.uuid]

    @models.permalink
    def get_delete_url(self):
        return 'account_delete', [self.uuid]

models.py:

{% extends 'base.html' %}

{% block content %}
    <div id="content-container" class="container p-none">
        <div id="ad-container">
            <div id="gi-container" class="ad-container">
                {% include 'accounts/account_item_view.html' %}
            </div>
        </div>
        {# List Contacts #}
        {# List Communications #}
    </div>

{% endblock %}

account_detail.html:

<div class="gi-header">
    <h3 class="ad-mh">{{ account.name }}
        {# Account Edit Link #}
        <span>
            <a class="ad-control edit-account btn btn-link"
               href="">Edit</a>
        </span>
    </h3>

</div>
<div class="row gi-body">
    <div class="col-md-9">
        <h5 class="gi-sh">Description</h5>
        <p>{{ account.desc }}</p>
    </div>
    <div class="col-md-3">
        <h5 class="gi-sh">Address</h5>
        <p class="nm">{{ account.address_one }}</p>
        <p class="nm">{{ account.address_two }}</p>
        <p class="nm">{{ account.city}}, {{ account.state }}</p>
        <p class="nm">{{ account.phone}}</p>
    </div>
</div>

account_item_view.html:

<!DOCTYPE html>
<html>

    <head>
        <title>Home  | CRM Easy</title>

            <link rel="icon" type="image/png"
                  href="/static/images/favicon.ico">



                <meta http-equiv="Content-Type"
                      content="text/html; charset=utf-8" />


                <meta http-equiv="Content-Language" value="en-US" />


                <meta name="viewport"
                      content="width=device-width, initial-scale=1.0">


        <!--


                <link href="/static/css/bootstrap.min.css"
                      rel="stylesheet" media="screen">
                <link href="/static/css/app.css"
                      rel="stylesheet" media="screen">




        -->
    </head>
    <body>

        <header>
            <div class="navbar navbar-default navbar-static-top
            ">
                <div class="container p-none">
                    <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 class="navbar-brand" href="/">CRM Easy</a>
                    </div>
                    <div class="collapse navbar-collapse">
                        <ul class="nav navbar-nav navbar-right">

                                <li><a href="/logout/">Logout</a></li>
                                <li><a href="/account/list/"
                                       class="p-r-none">Accounts</a></li>

                        </ul>
                    </div>
                </div>
            </div>
        </header>

        <div id="site-wrapper">

    <div id="content-container" class="container p-none">
        <div id="ad-container">
            <div id="gi-container" class="ad-container">
                <div class="gi-header">
    <h3 class="ad-mh">Test Account

        <span>
            <a class="ad-control edit-account btn btn-link"
               href="">Edit</a>
        </span>
    </h3>

</div>
<div class="row gi-body">
    <div class="col-md-9">
        <h5 class="gi-sh">Description</h5>
        <p>This is merely a test account for testing purposes</p>
    </div>
    <div class="col-md-3">
        <h5 class="gi-sh">Address</h5>
        <p class="nm">Test Street 1</p>
        <p class="nm"></p>
        <p class="nm">Test City, TE</p>
        <p class="nm">044 666 7777</p>
    </div>
</div>

            </div>
        </div>


    </div>


        </div>

        <div class="footer">
            <div class="container">
                <p>Copyright CRM Easy</p>
            </div>
        </div>
    </body>

    <!--


            <script src="/static/js/jquery.min.js"></script>
            <script src="/static/js/bootstrap.min.js"></script>
            <script src="/static/js/app.js"></script>




    -->
</html>

编辑:这是渲染的html,似乎是正确的

MappedDiagnosticsContext.Set("PropertyName", "PropertyValue");

1 个答案:

答案 0 :(得分:2)

问题是班级ad-container。 AdBlock认为该元素包含广告并将其删除。重命名该类将防止该问题。