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

Jinja #2

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ verify_ssl = true
name = "pypi"

[packages]
jinja2 = "==3.1.4"

[dev-packages]

Expand Down
96 changes: 96 additions & 0 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 5 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
# help_python
In this project,
I plan to use the libraries that exist in Python in different branches of this project.
I will also include Python mini-projects in this project.
In this branch we try to work with jinja library.
On raw Python, not Python frameworks like Django and Flask.

## Property's
- working with Multi Processing
- working with Multi Threading
- mini project python

## Installation and Setup
1. First, make sure you have Python and Pipenv installed on your system.
2. Install Pipenv by running the following command.
3. Next, navigate to your project directory and create the Pipenv virtual environment and install project dependencies.
4. Now, activate the Pipenv virtual environment and run your project scripts.

## Property's
- JINJA

```bash
$ pip install pipenv
$ cd help_python
$ pipenv install
$ pipenv shell
$ pipenv install Jinja2
```
Please note that these instructions serve as an example, and you should modify them based on your own project's requirements and settings. Additionally, if your project has specific dependency configurations, you can include those in the Pipfile and refer to it in the "Installation and Setup" section of your README.md file.
29 changes: 29 additions & 0 deletions start/data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class Person:
def __init__(self, *args, **kwargs):
self.name = kwargs['name']
self.family = kwargs['family']
self.age = kwargs['age']
self.email = kwargs['email']
self.phone = kwargs['phone']
self.address = kwargs['address']
self.birthday = kwargs['birthday']
self.gender = kwargs['gender']

person_1 = Person(name="amir", family='df', age=20, email="<EMAIL>", phone="02442424242", address="sdfsdfsddff", birthday="dfd", gender="female")
person_2 = Person(name="alice", family='df', age=20, email="<EMAIL>", phone="02442424242", address="sdfsdfsdf", birthday="sdfd", gender="female")

content = {
'person_1': person_1,
'person_2': person_2,
'name': 'Amir',
'age': 20,
'list': [1, 2, 3, 4, 5, 6, 7, 8, 9],
'dict': [
{'name': 'John', 'age': -12},
{'name': 'Aer', 'age': 23},
{'name': 'Jan', 'age': 19},
{'name': 'are', 'age': 40},
{'name': 'John', 'age': 42},
],
'text' : 'text tsext text sdfasdkfmaspklzcvns fdmknskofncvlnlsdkfm ls,dzxc vpioasnd fxcnm ndiofxc kosdf | ce',
}
11 changes: 11 additions & 0 deletions start/help
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
* ) filter

1) abs : Return the absolute value of the argument.

2) batch : A filter that batches items.

3) capitalize : The first character will be uppercase, all others lowercase.

4) center :

5) default :
16 changes: 16 additions & 0 deletions start/start.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from jinja2 import Environment, FileSystemLoader, select_autoescape
import data

env = Environment(
loader=FileSystemLoader('./templates'),
autoescape=select_autoescape()
)

template = env.get_template('index.html')
template_person = env.get_template('persons.html')


content = data.content

print(template.render(**content))
# print(template_person.render(**content))
26 changes: 26 additions & 0 deletions start/templates/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>
{% block title %}
base
{% endblock %}
</title>
</head>
<body>
HELLOW BASE
{% block content %}
default content
{% endblock %}


{% block inner %}
default inner
{% endblock %}

{% block person %}
class persons
{% endblock %}
</body>
</html>
24 changes: 24 additions & 0 deletions start/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% extends 'base.html' %}

{% block title %}
index
{% endblock %}


{% block inner %}
<h1>Hellow {{name|capitalize}} {{age}}</h1>
<p>list[0] : {{list[0]}}</p>
<div>
{% for item in dict %}
<h3>{{ item.name|capitalize }}</h3>
<h4>{{ item.age }}</h4>
{% endfor %}

<p>{{ text | center(4) }}</p>
{{ my_variable|default('my_variable is not defined') }}
</div>

<div>
sum age dics : {{ dict | sum(attribute = 'age') }}
</div>
{% endblock %}
18 changes: 18 additions & 0 deletions start/templates/persons.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{% extends 'base.html' %}

{% block person %}
<div>
<p>name : {{ person_1.name }}</p>
<p>family : {{ person_1.family }}</p>
<p>age : {{ person_1.age }}</p>
<p>phone : {{ person_1.phone }}</p>
<p>address : {{ person_1.address }}</p>
<p>birthday : {{ person_1.birthday }}</p>
<p>gender : {{ person_1.gender }}</p>


{% if person_2.age > 18 %}
<h1>age {{ person_2.name }} > 18.z</h1>
{% endif %}
</div>
{% endblock %}