# Django Code Result not Displaying with include

**URL:** <https://forum.djangoproject.com/t/django-code-result-not-displaying-with-include/27771>\
**Category:** Getting Started\
**Created:** [February 5, 2024, 2:14pm UTC](https://forum.djangoproject.com/t/django-code-result-not-displaying-with-include/27771 "2024-02-05T14:14:00Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![RobertWSON](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/robertwson/32/14481_2.png) [@RobertWSON](https://forum.djangoproject.com/u/RobertWSON)\
**Post date:** [February 5, 2024, 2:14pm UTC](https://forum.djangoproject.com/t/django-code-result-not-displaying-with-include/27771/1 "2024-02-05T14:14:00Z")

</div>

Why is it that when I use an include for an example on my page, there is no result from Django Code showing ?

![Django Code Result No Show](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/3X/2/8/28f6568e4b00f9b43fb759dc2707ce56d6434120.png)

With screenshot above, you can see between  
**Loop through items of a list:**  
and **In view.py you can see what cars variable looks like.**  
that there is no result showing from Django code

As a for loops main page, I have a `for_loops_tested.html` file and it uses include for different examples to show on one page, like this:

```auto
<h4>For Loop List Dictionaries Example</h4>
{% include 'testing/for_loop_dict.html' %}

```

`testing/for_loop_dict.html` looks like this:

```auto
<p>Loop through items of a list:</p>

{% for x in cars %}
  <h1>{{ x.brand }}</h1>
  <p>{{ x.model }}</p>
  <p>{{ x.year }}</p>
{% endfor %} 

<p>In views.py you can see what cars variable looks like.</p>

```

In `my views.py` it has this code:

```auto
def for_loop_dict(request):
  template = loader.get_template('testing/for_loop_dict.html')
  context = {
    'cars': [
      {
        'brand': 'Ford',
        'model': 'Mustang',
        'year': '1964',
      },
      {
        'brand': 'Ford',
        'model': 'Bronco',
        'year': '1970',
      },
      {
        'brand': 'Volvo',
        'model': 'P1800',
        'year': '1964',
      }]     
    } 
  return HttpResponse(template.render(context, request))

```

and for this example, this is urls.py

```auto
 path('testing/for_loop_tested', views.for_loop_tested, name='for_loop_tested'),
 path('testing/for_loop_tested', views.for_loop_dict, name='for_loop_dict'),

```

My understanding is that you can use `include tag` and `with` for variables together, but how is it meant to be done with an example I have shown that uses an array ?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [February 5, 2024, 2:21pm UTC](https://forum.djangoproject.com/t/django-code-result-not-displaying-with-include/27771/2 "2024-02-05T14:21:38Z")

</div>

> [@RobertWSON](#):
>
> ```auto
> path('testing/for_loop_tested', views.for_loop_tested, name='for_loop_tested'),
> path('testing/for_loop_tested', views.for_loop_dict, name='for_loop_dict'),
> 
> ```

A requested url is matched to the first matching path. You’re never going to call `views.for_loop_dict`. The only view that will be executed is `views.for_loop_tested`. Please post _that_ view.

---

<div class="post-metadata">

**Author:** ![RobertWSON](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/robertwson/32/14481_2.png) [@RobertWSON](https://forum.djangoproject.com/u/RobertWSON)\
**Post date:** [February 5, 2024, 2:39pm UTC](https://forum.djangoproject.com/t/django-code-result-not-displaying-with-include/27771/3 "2024-02-05T14:39:22Z")

</div>

Hi Ken

This is `for_loop_tested` view

```auto
def for_loop_tested(request):
    template = loader.get_template('testing/for_loop_tested.html')
    context = {
       'fruits': ['Apple', 'Banana', 'Cherry'],
    }
    return HttpResponse(template.render(context, request))

```

This is used to display my [http://127.0.0.1:8000/testing/for\_loop\_tested](http://127.0.0.1:8000/testing/for_loop_tested) page below  
and the first example that shows Apple, Banana and Cherry

 ![for loops tested Page](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/3X/b/2/b2043e8802b0e0d09993907ebc6686151829de5a.png)  
You see, what I am trying to do is have that showing and then use include for examples below first fruits example like the For List Dictionaries Example that explained was not showing currently.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [February 5, 2024, 2:42pm UTC](https://forum.djangoproject.com/t/django-code-result-not-displaying-with-include/27771/4 "2024-02-05T14:42:20Z")

</div>

Your `for_loop_tested` view doesn’t define a context variable named `cars`, so there’s nothing for the template to display.

---

<div class="post-metadata">

**Author:** ![RobertWSON](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/robertwson/32/14481_2.png) [@RobertWSON](https://forum.djangoproject.com/u/RobertWSON)\
**Post date:** [February 5, 2024, 3:00pm UTC](https://forum.djangoproject.com/t/django-code-result-not-displaying-with-include/27771/5 "2024-02-05T15:00:27Z")

</div>

How can I have both of these examples (fruits and cars) showing on same [http://127.0.0.1:8000/testing/for\_loop\_tested](http://127.0.0.1:8000/testing/for_loop_tested) page ?

One thing I have noticed is that my for\_loop\_dict.html file is white in colour as can be seen below

 ![for loop dict File White Colour](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/3X/e/3/e37eb96bd555402e7f39c176e0a60e2bb2d79e26.png)

Would I be better to have a view for whole page like this

```auto
def for_loop_tested(request):
  template = loader.get_template('testing/for_loop_tested.html')
  return HttpResponse(template.render())

```

and then have separate views for **Loop through items of a list** and **Loop through a list of dictionaries** examples.

Then the views don’t clash.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [February 5, 2024, 3:14pm UTC](https://forum.djangoproject.com/t/django-code-result-not-displaying-with-include/27771/6 "2024-02-05T15:14:02Z")

</div>

Focus on the fundamentals of the HTTP request/response cycle.

When the browser issues a request for a URL, what you get back is _one_ page.

When Django receives that URL being requested, it is going to search through the defined URLs to find the first URL that matches the requested URL. It will then call that _one_ view associated with that path.

That view will return _one_ HttpResponse (or subclass thereof).

Everything that will be in that HttpResponse needs to be created by _that_ view, including other functions it may call.

That means that _that_ view needs to retrieve or create all data to be rendered on that page, and render all templates that are needed to produce that page.

How you do that is up to you.

You need to decide what the contents of a page are going to be, then create the view and template(s) to produce that page.

---

<div class="post-metadata">

**Author:** ![RobertWSON](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/robertwson/32/14481_2.png) [@RobertWSON](https://forum.djangoproject.com/u/RobertWSON)\
**Post date:** [February 7, 2024, 11:37am UTC](https://forum.djangoproject.com/t/django-code-result-not-displaying-with-include/27771/7 "2024-02-07T11:37:34Z")

</div>

It is interesting to note that with another example on that same page [http://127.0.0.1:8000/testing/for\_loop\_tested#last](http://127.0.0.1:8000/testing/for_loop_tested#last) , it displays a result from code I have used.  
However I have noticed that it is using  
`'fruits': ['Apple', 'Banana', 'Cherry'],` from first example that uses `for_loop_tested view`.

This indicates to me that there is a clash with views.

![For Loop Last Example](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/3X/b/3/b3c7182d5da897c3eaa2844fa6e9361b724b516c.png)

In for loops main page for\_loops\_tested.html it uses include like this:

```auto
<h3 id="last">forloop.last</h4>

<p>Allows you to test if a loop is on its last iteration.</p>

<h4>For Loop Last Example</h4>

<p>Draw a blue background for last iteration of a loop:</p>

{% include 'testing/for_loop_last.html' %}

```

Here is include File for\_loop\_last.html

```auto
<ul>
    {% for x in fruits %}
        <li
            {% if forloop.last %}
                style='background-color:lightblue; width:50px;'
            {% endif %}
        >{{ x }}</li>
    {% endfor %}        
</ul>

<p>In views.py you can see what fruits object looks like.</p>

```

Here is views.py :

```auto
def for_loop_last(request):
    template = loader.get_template('testing/for_loop_last.html')
    context = {
        'fruits': ['Apple','Banana','Cherry', 'Oranges', 'Kiwi']
    } 
    return HttpResponse(template.render(context, request))

```

and in urls.py I have:  
`path('testing/for_loop_tested', views.for_loop_last, name='for_loop_last'),`

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [February 7, 2024, 11:43am UTC](https://forum.djangoproject.com/t/django-code-result-not-displaying-with-include/27771/8 "2024-02-07T11:43:54Z")

</div>

> [@RobertWSON](#):
>
> This indicates to me that there is a clash with views.

That’s what I pointed out to you in my very first reply at [Django Code Result not Displaying with include - #2 by KenWhitesell](https://forum.djangoproject.com/t/django-code-result-not-displaying-with-include/27771/2)

---

<div class="post-metadata">

**Author:** ![RobertWSON](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/robertwson/32/14481_2.png) [@RobertWSON](https://forum.djangoproject.com/u/RobertWSON)\
**Post date:** [February 7, 2024, 11:58am UTC](https://forum.djangoproject.com/t/django-code-result-not-displaying-with-include/27771/9 "2024-02-07T11:58:16Z")

</div>

As I was asking before, would I be better to have a view for whole page [http://127.0.0.1:8000/testing/for\_loop\_tested](http://127.0.0.1:8000/testing/for_loop_tested) like this:

```auto
def for_loop_tested(request):
     template = loader.get_template('testing/for_loop_tested.html')
     return HttpResponse(template.render())

```

and then have separate views for each of the examples like I have shown on this post.

It should also be noted that I have a link in my template.html file to an example id on page like this

```auto
<tr>
      <td><a href="/testing/for_loop_tested#last">forloop.last</a></td>
      <td>Allows you to test if the loop is on its last iteration.</td>
</tr>

```

Links come from this testing page shown below:

 ![Django For Loop Section Links](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/3X/2/2/223951059d2e4ad08d9487ea44c62b0e3bf6621d.png)

and this is why I have more than one view with a path  
`path('testing/for_loop_tested', views.for_loop_last, name='for_loop_last'),`

All examples are on the same page [http://127.0.0.1:8000/testing/for\_loop\_tested](http://127.0.0.1:8000/testing/for_loop_tested) , but what separates them is an id in a heading for each example, as can be seen in this reply.

Can paths be done with id to different sections on a page ?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [February 7, 2024, 12:00pm UTC](https://forum.djangoproject.com/t/django-code-result-not-displaying-with-include/27771/10 "2024-02-07T12:00:50Z")

</div>

You ask me what you should do, but I don’t understand what your objective is for the page.

One view creates one page. One view does not call multiple views to create a page.

For any one page, your view needs to create or obtain all the data needed to be rendered on that page, and then render the templates.

---

<div class="post-metadata">

**Author:** ![RobertWSON](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/robertwson/32/14481_2.png) [@RobertWSON](https://forum.djangoproject.com/u/RobertWSON)\
**Post date:** [February 7, 2024, 12:42pm UTC](https://forum.djangoproject.com/t/django-code-result-not-displaying-with-include/27771/11 "2024-02-07T12:42:42Z")

</div>

I don’t think you quite see what I am wanting to achieve with this.

I have a [http://127.0.0.1:8000/testing/](http://127.0.0.1:8000/testing/) page that has different sections.  
I am talking about the for loop section that is in screenshot below

 ![Django For Loop Section Links](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/3X/2/2/223951059d2e4ad08d9487ea44c62b0e3bf6621d.png)

You see `For Loops link` goes to `http://127.0.0.1:8000/testing/for_loop_tested page`.  
Here is the key to understanding this, all links below the top one go to a specific part on `http://127.0.0.1:8000/testing/for_loop_tested page` and this is done with an `id`.

Now I was mentioning that I thought I may have to change my view for the first `For Loops link`, so that it is like this

```auto
def for_loop_tested(request):
     template = loader.get_template('testing/for_loop_tested.html')
     return HttpResponse(template.render())

```

and have all `examples` as `separate views` and `note` `separate html files` that can be used with `include` in `for_loop_tested.html`.

I have seen that `include` and `with` can be used together in Django.

You know `{% include 'testing/for_loop_last.html' %}`  
, but I believe you can also use `with` in `include`, I am just asking a question now, how can this be done with my examples like cars and fruits array ?

Surely Django should be able to do want I want to achieve ?

I appreciate your help so far, just want to move forward and get this working correctly, thanks.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [February 7, 2024, 1:07pm UTC](https://forum.djangoproject.com/t/django-code-result-not-displaying-with-include/27771/12 "2024-02-07T13:07:24Z")

</div>

What I think I’m understanding you to say:

You want to create a page, containing internal links to other parts of the same page.

However, you don’t want those other parts to be in the same template as your main page.

Is that correct? If so, then you can use include to include those different templates in your page. (And, I don’t understand where the “data” components come into this.)

(If I’m not correct, then I’m sorry, but it’s still not clear what you’re really trying to do here. It may be more helpful if you were more specific with your objective rather than trying to address this through an analogy. It may also be helpful if you just started with defining what _all_ you want on this page, rather than trying to discuss how you think you want to create it.)

---

<div class="post-metadata">

**Author:** ![RobertWSON](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/robertwson/32/14481_2.png) [@RobertWSON](https://forum.djangoproject.com/u/RobertWSON)\
**Post date:** [February 8, 2024, 11:36am UTC](https://forum.djangoproject.com/t/django-code-result-not-displaying-with-include/27771/13 "2024-02-08T11:36:44Z")

</div>

I thought I would mention now that I have actually had these pages setup already, but problem is that Django Code in my include file is not working for examples.  
So this means that I am not getting anything displayed with examples, hopefully this makes sense.

Yes you are correct.

The main page that has all links to one page is this one.

 ![Django For Loop Section Links](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/3X/2/2/223951059d2e4ad08d9487ea44c62b0e3bf6621d.png)

and page these links go to is this page below.

 ![For Loop Tested Page](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/3X/5/a/5a83b5f804a246e93532c67da8ada0a0fd0117b4.png)

As you can see on this [http://127.0.0.1:8000/testing/for\_loop\_tested](http://127.0.0.1:8000/testing/for_loop_tested) page Django Examples are not displaying except result from

 tags.

Hopefully this makes sense.

I just wonder if something in settings needs to be adjusted, so that Django Code can be recognised from an include file.

In my next reply I will show you some of my code I have pushed to GitHub, in particular include file.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [February 8, 2024, 12:06pm UTC](https://forum.djangoproject.com/t/django-code-result-not-displaying-with-include/27771/14 "2024-02-08T12:06:59Z")

</div>

Ok, I think I’m closer.

Again rephrashing to hopefully show understanding.

You have “View 1”. This view renders a template, “Template 1”.

“Template 1” includes “Template 2”. You want “Template 2” to contain data generated by “View 2”.

I think this is the gist of what you’re trying to achieve.

If so: **No**. It doesn’t work that way.

Templates don’t “call” views to be executed - the flow of control is only in the opposite direction. Views render templates.

If this is the situation you’re trying to achieve, then “View 1” needs to create or acquire **all** data needed to render “Template 1”, “Template 2”, etc.

You are calling **one** view to generate this page. You are not calling any other views.

---

<div class="post-metadata">

**Author:** ![RobertWSON](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/robertwson/32/14481_2.png) [@RobertWSON](https://forum.djangoproject.com/u/RobertWSON)\
**Post date:** [February 8, 2024, 12:09pm UTC](https://forum.djangoproject.com/t/django-code-result-not-displaying-with-include/27771/15 "2024-02-08T12:09:59Z")

</div>

On GitHub in my `for_loop_tested.html` file I have a [First List Item Example](https://github.com/RobertWSON/django-learning/blob/main/W3Schools-Django/my_tennis_club/members/templates/testing/for_loop_tested.html#L32)  
I have used include like this for this example `{% include 'testing/for_loop_item.html' %}`

and in `for_loop_item.html` file I have used this code below

```auto
{% for x in fruits %}
    <h1>{{ x }}</h1>
{% endfor %}

<p>In views.py you can see what fruits variable looks like.</p>

```

But what I get displaying is just  
`In views.py you can see what fruits variable looks like.`

I think you can see from this example that problem is Django code is not displaying.

Another example [Second List Dictionary Example](https://github.com/RobertWSON/django-learning/blob/main/W3Schools-Django/my_tennis_club/members/templates/testing/for_loop_tested.html#L36)  
I have used include like this for this example {% include ‘testing/for\_loop\_dict.html’ %}

and in `for_loop_dict.html` file I have used this code below

```auto
<p>Loop through a list of dictionaries:</p>

{% for x in cars %}
  <h1>{{ x.brand }}</h1>
  <p>{{ x.model }}</p>
  <p>{{ x.year }}</p>
{% endfor %} 

<p>In views.py you can see what cars variable looks like.</p>

```

But what I get displaying is

```auto
Loop through a list of dictionaries:

In views.py you can see what fruits variable looks like.

```

This indicates to me that html code from my include file works, but not Django Code.  
I am not sure how to fix this, but as I mentioned before could it be in my [settings.py](https://github.com/RobertWSON/django-learning/blob/main/W3Schools-Django/my_tennis_club/my_tennis_club/settings.py) that this can be fixed.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [February 8, 2024, 12:12pm UTC](https://forum.djangoproject.com/t/django-code-result-not-displaying-with-include/27771/16 "2024-02-08T12:12:00Z")

</div>

It’s not the settings.

What you are trying to do here is fundamentally incorrect.

For your example here:

> [@RobertWSON](#):
>
> ```auto
> {% for x in cars %}
> <h1>{{ x.brand }}</h1>
> <p>{{ x.model }}</p>
> <p>{{ x.year }}</p>
> {% endfor %} 
> 
> ```

Your view that is rendering **this** page must provide the entry “cars” in your context.

No other view is involved here.

(You are also not showing “Django code” at all - that’s an incorrect phrasing of what’s happening here. You are rendering variables from a context.)

(Side note: If you’re trying to learn Django from W3Schools, don’t. Use better resources. Start with either or both of the [Official Django Tutorial](https://docs.djangoproject.com/en/4.2/intro/tutorial01/) and the [Django Girls Tutorial](https://tutorial.djangogirls.org/en/). Then find resources at [GitHub - wsvincent/awesome-django: A curated list of awesome things related to Django](https://github.com/wsvincent/awesome-django?tab=readme-ov-file#educational))

---

<div class="post-metadata">

**Author:** ![RobertWSON](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/robertwson/32/14481_2.png) [@RobertWSON](https://forum.djangoproject.com/u/RobertWSON)\
**Post date:** [February 8, 2024, 12:35pm UTC](https://forum.djangoproject.com/t/django-code-result-not-displaying-with-include/27771/17 "2024-02-08T12:35:41Z")

</div>

Views for `http://127.0.0.1:8000/testing/for_loop_tested` page  
and 2 examples I have been talking about are in my `views.py` file from lines [643 to 692](https://github.com/RobertWSON/django-learning/blob/main/W3Schools-Django/my_tennis_club/members/views.py#L643)  
and I have

```auto
from django.http import HttpResponse
from django.template import loader

```

at top of views.py on lines [44 to 47](https://github.com/RobertWSON/django-learning/blob/main/W3Schools-Django/my_tennis_club/members/views.py#L44)

I have a lot of comments, but you can ignore them as that is just to keep track of what is going on.

I have seen your last reply, it just seems like it isn’t that easy to get all these examples displaying correctly on one page.

How can this be done with Django ?

I have spent some time getting this done and I hope that I can get it completed in a way that works well.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [February 8, 2024, 12:38pm UTC](https://forum.djangoproject.com/t/django-code-result-not-displaying-with-include/27771/18 "2024-02-08T12:38:14Z")

</div>

> [@RobertWSON](#):
>
> it just seems like it isn’t that easy to get all these examples displaying correctly on one page.

It is. Just include all the code that generates the data in the one view.

Or, if you still want separate and independent pages to display these examples, refactor your code such that you have a function for each example. Call all the functions in your view that generates the “big” page, and each view that generates a single page calls the appropriate function.

---

<div class="post-metadata">

**Author:** ![RobertWSON](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/robertwson/32/14481_2.png) [@RobertWSON](https://forum.djangoproject.com/u/RobertWSON)\
**Post date:** [February 8, 2024, 12:52pm UTC](https://forum.djangoproject.com/t/django-code-result-not-displaying-with-include/27771/19 "2024-02-08T12:52:58Z")

</div>

Maybe you are right, there must be a nice efficient way like you are mentioning to do it.

I just wonder when all examples have different views how to deal with this.

You mention include all code that generates data in one view.  
How does this work ?

W3Schools has [Django for Tag](https://www.w3schools.com/django/django_tags_for.php) on one page with examples for that topic and I think that this the best way to do it because you want examples all related to a topic.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [February 8, 2024, 1:04pm UTC](https://forum.djangoproject.com/t/django-code-result-not-displaying-with-include/27771/20 "2024-02-08T13:04:47Z")

</div>

We actually have two different situations here that I would handle in two different ways.

When you’re talking about a reference page - something that is showing you a static example and results, I would create this page with the actual html. I would _not_ try to render data for each page retrieval. If I were building documentation for things like this, that is how _I_ would do it. (It serves no purpose to go through the rendering process when that page is always going to show the same information.)

However, if you’re talking about a real project, where you’re showing live data, then you want to build your context from all the resources necessary for that page.

> [@RobertWSON](#):
>
> How does this work ?

Something like this:

```auto
def my_view(request):
    context = {}
    context['fruit'] = [...]
    context['cars'] = { ... }
    ...
    return render(request, template, context)

```

Side note: If you’ve learned this  
`template = ...`  
`template.render(...`  
pattern from this tutorial, it’s badly out of date. You really should be working from current / vetted material.

[Next page](https://forum.djangoproject.com/t/django-code-result-not-displaying-with-include/27771.md?page=2)
