I want to make a custom include tag (like `{% smart_include something %}` ), which realize what kind a thing we want to include and then call regular `{% include %}` tag. That's should be something like this:

```
@register.simple_tag
def smart_include(something):
    if something == "post":
          template_name = "post.html"
          return regular_include_tag(template_name)

```

Is there a way to use `{% include %}` tag in python code, and how exactly?

**UPD.** turn's out, the best way to solve this problem is just use `render_to_string` shortcut
['https://Stackoverflow.com/questions/8412710', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/277262/']
I assume there is a reason why you are not doing:

```
{% if foo %}
  {% include 'hello.html' %}
{% endif %}

```

If `something` is a fixed number, you can use [inclusion tags](https://docs.djangoproject.com/en/dev/howto/custom-template-tags/#howto-custom-template-tags-inclusion-tags). In your template instead of `{% smart_tag something %}`, you have `{% something %}`, then your tag library looks like this:

```
@register.inclusion_tag('post.html')
def something():
    return {} # return an empty dict

```

Finally, you can replicate the functionality of the include tag. This snippet should point you in the right direction:

```
filepath = '/full/path/to/your/template/%s' % something
try:
   fp = open(filepath, 'r')
   output = fp.read()
   fp.close()
except IOError:
   output = ''
try:
   t = Template(output, name=filepath)
   return t.render(context)
except TemplateSyntaxError, e:
   return '' # Fail silently.
return output

```
`render_to_string` will render the given template\_name to an html string

```py
from django.template.loader import render_to_string

template_name = 'post.html'
optional_context = {}
html = render_to_string(template_name, optional_context)

```