-1
  • I need to use that function below, here is in util.py

    def get_entry(title):
        try:
            f = default_storage.open(f"entries/{title}.md")
            return f.read().decode("utf-8")
        except FileNotFoundError:
            return None
    
  • Then I put that in my views.py with the var "get"

    def getFunction(request):
        return render(request, "encyclopedia/index.html", {
            "get": util.get_entry()  
        })   
    
  • So I want to use that function in my index.html

    {% block body %}
        <h1>All Pages</h1>
    
        <ul>
            {% for entry in entries %}
                <a href="{% get %}"><li>{{ entry }}</li></a> //{% get %} doesn't work
            {% endfor %}
        </ul>
    {% endblock %}
    
  • The only for is to show up a list with 5 items and inside of li, using entry I can display all five items (e.g: apple, banana, tomato, pear, grape)

  • I need to use href because When I click it will to another folder/file .md that will be writed about apple for example

  • I wanna use that function to take in my file .md

  • If you need more informations just ask me. thank u. :)

Abdul Aziz Barkat
  • 19,475
  • 3
  • 20
  • 33
  • Does this answer your question? [How to call function that takes an argument in a Django template?](https://stackoverflow.com/questions/2468804/how-to-call-function-that-takes-an-argument-in-a-django-template) – Abdul Aziz Barkat Sep 28 '22 at 04:27

2 Answers2

0

You can add an @property on models.py for the app the call entries.your_function

Adetoro Lanre
  • 43
  • 1
  • 4
0

You can try this

class YourModel(models.Model):

    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=200)

    # Add a property to your model
    @property
    def yourFunction(self):
        # steps
        return 'Hello from your template!'

Next just call it like this in your template

{{ your_model_instance.yourFunction }}

You will see

Hello from your template!