jinja2 variables naming - Are variables naming restrictions the same as for Python variables?

2024/9/19 9:44:20

I did't find it written explicitly in the docs.

Are the naming rules the same as with Python variables?

(eg: {{ a_variable'like_that' }} doesn't work for example)

Answer

Jinja's naming convention generally matches your python interpreter's identifiers. So it also depends on your Python version (2.x: like [a-zA-Z_][a-zA-Z0-9_]*)

(source: #pocoo on irc.freenode.net)

https://en.xdnf.cn/q/72763.html

Related Q&A

What does t /= d mean? Python and getting errors

// t: current time, b: begInnIng value, c: change In value, d: durationdef: easeOutQuad, swing: function (x, t, b, c, d) {//alert(jQuery.easing.default);return jQuery.easing[jQuery.easing.def](x, t, b,…

Python File Read + Write

I am working on porting over a database from a custom MSSQL CMS to MYSQL - Wordpress. I am using Python to read a txt file with \t delineated columns and one row per line.I am trying to write a Python …

Uploading a file via pyCurl

I am trying to convert the following curl code into pycurl. I do not want to use requests. I need to use pycurl because requests is not fully working in my old python version.curl -X POST -H "Acce…

Speed up computation for Distance Transform on Image in Python

I would like to find the find the distance transform of a binary image in the fastest way possible without using the scipy package distance_trnsform_edt(). The image is 256 by 256. The reason I dont wa…

Prevent Kivy leaving debug messages

I have a simple a Kivy interface that also uses the terminal. Example code:import kivykivy.require(1.0.6)from kivy.app import App from kivy.uix.label import Labelclass MyApp(App):def build(self):return…

django.db.utils.InternalError: (1050, Table django_content_type already exists)

django.db.utils.InternalError: (1050, "Table django_content_type already exists")I just copied a project from my friend, when I run makemirations it runs properly. But for - python3 manage.py…

Use SQLites backup API from Python/SQLAlchemy

Im using an SQLite database from python (with SQLAlchemy). For performance reasons, Id like to populate an in-memory database in the application, and then back up that database to disk.SQLite has a bac…

ABC for String?

I recently discovered abstract base classes (ABCs) in collections and like their clear, systematic approach and Mixins. Now I also want to create customs strings (*), but I couldnt find an ABC for stri…

Get the most relevant word (spell check) from enchant suggest() in Python

I want to get the most relevant word from enchant suggest(). Is there any better way to do that. I feel my function is not efficient when it comes to checking large set of words in the range of 100k or…

How do I get python-markdown to additionally urlify links when formatting plain text?

Markdown is a great tool for formatting plain text into pretty html, but it doesnt turn plain-text links into URLs automatically. Like this one:http://www.google.com/How do I get markdown to add tags …