how to return simple function in django html file?
Question: I need return calculate_c value in html

urls.py

    
    
    from django.conf.urls import include, url
    from . import views
    
    urlpatterns = [
        url(r'^$', views.my_view, name='my_view'),
    
    ]
    

views.py

    
    
    from django.shortcuts import render
    from django.http import HttpResponse
    
    def abc():
        a = 1
        b = 3
        calculate_c = a + b
        return calculate_c
    
    def my_view(request):
        context = {'calculated_value': 0}
        context['calculated_value'] = abc()
        return HttpResponse(request, 'blog/post_list.html', context)
    

post_list.html

    
    
    {% extends 'blog/base.html' %}
    
    {% block content %}
    
    <h2>{{calculated_value}}</h2>
    <h2>Test</h2>
    
    {% endblock %}
    

Internal Server Error: / Traceback (most recent call last): File
"/home/v1/newproject/newenv/lib/python3.4/site-
packages/django/core/handlers/base.py", line 242, in get_response response =
self.apply_response_fixes(request, response) File
"/home/v1/newproject/newenv/lib/python3.4/site-
packages/django/core/handlers/base.py", line 305, in apply_response_fixes
response = func(request, response) File
"/home/v1/newproject/newenv/lib/python3.4/site-packages/django/http/utils.py",
line 17, in conditional_content_removal if 100 <= response.status_code < 200
or response.status_code in (204, 304): TypeError: unorderable types: int() <=
dict()


Answer: If you need the value returned by `adc()` in your template, you could pass it
via `context`:

    
    
    def my_view(request):
    
        ...
        context = {...}
        context['calculated_value'] = abc()
        return render(request, 'blog/post_list.html', context)
    

And then in your template you can use:

    
    
    {{ calculated_value }}
    

