包含的页面不会显示其完整内容

时间:2015-10-15 09:34:46

标签: python django django-templates django-views

我想在另一个页面中包含一个名为group_sharer.html的页面:

this is the page which i'll include in the home page

 {% include "group_sharer.html" %}

我试图用

将它包含在主页中
   public void FillDocument(Stream stream, XDocument document)
   {                
   using (WordprocessingDocument wordDocument =
            WordprocessingDocument.Open(stream, true))
        {
            List<SdtElement> descendants = wordDocument.MainDocumentPart.Document.Descendants<SdtElement>().ToList();
            foreach (var headerPart in wordDocument.MainDocumentPart.HeaderParts)
            {
                 descendants.AddRange(headerPart.Header.Descendants<SdtElement>().ToList());
            }
            foreach (var footerPart in wordDocument.MainDocumentPart.FooterParts)
            {
                descendants.AddRange(footerPart.Footer.Descendants<SdtElement>().ToList());
            }

            XDocument doc = document;

            foreach (SdtElement item in descendants)
            {
                SdtAlias alias = item.Descendants<SdtAlias>().FirstOrDefault();

                if (alias != null)
                {                                         
                    string sdtTitle = alias.Val.Value;

                    //if Sdt Content Control is Picture
                    string imageContent = (from xElement in doc.Descendants("Picture") where xElement.Attribute("Id").Value == sdtTitle select xElement.Value).FirstOrDefault();
                    if (imageContent != null)
                    {
                        MemoryStream result = (MemoryStream)StringToStream(imageContent);

                        SdtProperties p = item.Elements<SdtProperties>().FirstOrDefault();
                        if (p != null)
                        {
                            // Is it a picture content control?
                            SdtContentPicture pict = p.Elements<SdtContentPicture>().FirstOrDefault();
                            // Get the alias.
                            SdtAlias a = p.Elements<SdtAlias>().FirstOrDefault();
                            if (pict != null && a.Val.Value == sdtTitle)
                            {
                                string embed = null;
                                Drawing dr = item.Descendants<Drawing>().FirstOrDefault();
                                if (dr != null)
                                {
                                    D.Blip blip = dr.Descendants<D.Blip>().FirstOrDefault();
                                    if (blip != null)
                                        embed = blip.Embed;
                                    if (embed != null)
                                    {
                                        IdPartPair idpp = wordDocument.MainDocumentPart.Parts
                                            .Where(pa => pa.RelationshipId == embed).FirstOrDefault();
                                        if (idpp != null)
                                        {
                                            ImagePart ip = (ImagePart)idpp.OpenXmlPart;
                                            ip.FeedData(result);
                                        }
                                    }
                                }
                            }
                        }



                        continue;
                    }

    }
}

但它没有提供完整的数据

And this is the home page

我应该知道如何将Group_sharer.html中的数据实现到主页。

1 个答案:

答案 0 :(得分:0)

您的代码是正确的,缺少的是campaigns

由于您需要这些,您还需要将此上下文传递给包含它的模板。

来自the docs

  

包含的模板在包含它的模板的上下文中呈现。