question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`self` variable is not defined

See original GitHub issue

Hi,

The following code triggers an error (), is it normal ? It works fine in jinja :

{% block test %}{% endblock %}
{{ self.test() }}

(self.test() should return the content of the test block, especially useful when you want to wrap contents such as in the following example)

{% if self.test() | trim != "" %}
    <div class="wrapper">
        {% block test %}{% endblock %}
    </div>
{% endif %}

Issue Analytics

  • State:open
  • Created 10 years ago
  • Reactions:17
  • Comments:15

github_iconTop GitHub Comments

2reactions
wolframkriesingcommented, Dec 29, 2020

My workaround is in the place where the block’s content wants to be used multiple times.

Instead of

<title>{% block pageTitlePrefix %}{% endblock %}</title>

I am doing

{% set pageTitlePrefix %}{% block pageTitlePrefix %}{% endblock %}{% endset %}
<meta name="twitter:title" content="{{ pageTitlePrefix }}" />
<title>{{ pageTitlePrefix }}</title>

this makes pageTitlePrefix also a variable and that can be used any number of times. As long as the self.* thingy does not exist I am quite happy with this. Maybe worth mentioning in the docs.

0reactions
dylmyecommented, Oct 28, 2018

any update?

Read more comments on GitHub >

github_iconTop Results From Across the Web

python global name 'self' is not defined - Stack Overflow
self is the self-reference in a Class. Your code is not in a class, you only have functions defined. You have to wrap...
Read more >
NameError: name 'self' is not defined in Python [Solved]
To solve the NameError: name 'self' is not defined, make sure you haven't forgotten to specify the `self` argument in a method and...
Read more >
Python NameError: name 'self' is not defined - Softhints
Common errors for beginners related to self in Python is: NameError: name 'self' is not defined The keyword self is a special one...
Read more >
self is not defined? (Example) | Treehouse Community
So to answer your question. Self is not defined because the init method doesn't start with self. And your n value also has...
Read more >
python: self.variable within function [closed]
Should those k , y , and z be defined as __init__ . variables or not? What should be the difference between the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found