使用 django-page-cms 显示页面内容

发布于 2024-09-25 16:04:48 字数 1185 浏览 0 评论 0原文

我想在我的一些模板页面中显示位于我的模型中的一些内容。

我正在使用 django-page cms

在文档视图中不用于显示内容。相反,使用现成的模板标签。

http://packages.python.org/django-page-cms/display -content.html

我一个字都听不懂。请容忍我,我是新人。

我想要做的就是以这种方式在模板内显示位于我的模型中的一些信息。

 {% iflatest_news_list %}          
      {% 最新消息列表中的新闻 %} 
           
  • {{ news.title }}

  • {{ news.body }}

  • {% 结束 %}

    由于未使用视图,因此我无法使用latest_news_list。 我需要以某种方式让我的模型使用 django-page cms 而不是常规视图显示在模板中。该文档指出为此使用某种模板标签。

    有人可以向我解释一下如何做到这一点吗?
    并且对以下现成的模板标签进行清晰简洁的解释也将不胜感激...... * 获取内容 * 显示内容 * 获取页面 * show_absolute_url

    取自http://packages.python.org/django-page-cms/display-content.html

    我需要以上面突出显示的方式显示使用以下模型包含的信息。非常感谢您的帮助。我的模型如下。

    class Body(models.Model):
        type = models.ForeignKey(Content)
        title = models.CharField(max_length=100)
        published = models.DateTimeField(default=datetime.now)
        body = tinymce_models.HTMLField("Main content")
    

    正如我所说,我对此很陌生,请尽可能简单地进行解释。

    I would like to display some content located in my models in some of my template pages.

    I am using django-page cms

    In the documentation views are not used to display content. Instead ready made template tags are used.

    http://packages.python.org/django-page-cms/display-content.html

    I do not understand a word of this. Please Bear with me I am new.

    All I want to do is display some info located in my models inside a template this manner..

       {% if latest_news_list %}          
          {% for news in latest_news_list %} 
               <li><h3>{{ news.title }}</h3></li>
               <li><p>{{ news.body }}</p></li>
          {% endfor %}
    

    Since views are not used I cannot use if latest_news_list.
    I need to somehow get my models to display in the templates using django-page cms and NOT regular views. The documentation states to use some kind of template tag for this.

    Could somebody please explain to me how to do this.
    And a clear concise explanation of the following ready-made template tags would also be appreciated...
    * get_content
    * show_content
    * get_page
    * show_absolute_url

    taken from.http://packages.python.org/django-page-cms/display-content.html

    I need to display info contained using the following models in the manner I have highlighted above. Thank you very much for your help. my models are as follows.

    class Body(models.Model):
        type = models.ForeignKey(Content)
        title = models.CharField(max_length=100)
        published = models.DateTimeField(default=datetime.now)
        body = tinymce_models.HTMLField("Main content")
    

    As I have stated I am very new to this please make explanations as simple as possible.

    如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

    扫码二维码加入Web技术交流群

    发布评论

    需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

    评论(1

    ≈。彩虹 2024-10-02 16:04:48

    您提到的模板标签应该显示来自 cms 的内容。如果您想包含来自应用程序的数据,您应该看到此部分链接文本

    def extra_context():
        from myapp.models import Body
        items = Body.object.all()
        return {'items': items}
    
    PAGE_EXTRA_CONTEXT = extra_context
    
    
    {% if items %}
        <ul>
            {% for item in items %}
            <li>{{ item.title }} </li>
            {% endfor %}
        <ul>
    {% endif %}
    

    或者,如果您想使用应用程序的视图,请参阅此。

    The template tags you mentioned are supposed to display content coming from the cms. If you want to include data coming from your app, you should see this sectionlink text.

    def extra_context():
        from myapp.models import Body
        items = Body.object.all()
        return {'items': items}
    
    PAGE_EXTRA_CONTEXT = extra_context
    
    
    {% if items %}
        <ul>
            {% for item in items %}
            <li>{{ item.title }} </li>
            {% endfor %}
        <ul>
    {% endif %}
    

    Or, if you want to use your app's view, see this.

    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文