Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coding style for Django template code #217

Open
hongquan opened this issue Jun 26, 2024 · 2 comments
Open

Coding style for Django template code #217

hongquan opened this issue Jun 26, 2024 · 2 comments

Comments

@hongquan
Copy link
Member

hongquan commented Jun 26, 2024

To help IDE highlight code better, please don't use the same quote style when nesting.

Please write:

<a href="{% url 'some_view' %}">

Don't write:

<a href="{% url "some_view" %}">

Later on, I suggest to use djLint to lint Django template code.

Another good move is to use Jinja2 for template, because Jinja2 support more Python syntax. One typical case is that, when you want to manipulate a variable, you use filter:

{{ value|make_fancy }}

and what if you want to pass more options to make_fancy filter? With Django template, you can only pass one more option:

{{ value|make_fancy:'green' }}

But with Jinja2, you can just use Python function call syntax, and can pass as many as you want

{{ make_fancy(value, color='green', italic=True, border=2) }}

Another good feature of Jinja2 is "macro" which let you factorize your template to reusable parts, like functions.

@Vasudha299
Copy link

i would like to work on the documentation part

@Vasudha299
Copy link

Use Meaningful and Consistent Naming Conventions
Use clear, descriptive names for variables and blocks.
Stick to consistent naming patterns that match the project's coding style.
{% block content %}

{% endblock %}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants