Python Data into HTML Template

Hi ,

I need to change the menu list (when clicking the gravatar) when login into the Website according to the Roles of the user.

The menu list I mean,

  • MY Account
  • Logout

When I examined, I came to know that the menu comes from the navbar_login.html file

But it shows

<ul class="dropdown-menu" role="menu">
		{%- for child in post_login -%}
		<li {% if child.label %}data-label="{{ child.label }}" {% endif %}
			{% if child.class %} class="{{ child.class }}" {% endif %}>

			{%- if child.url -%}
				<a href="{{ child.url | abs_url }}" {{ or '' }}
					{{ child.label }}           <!-- My account, Logout -->
			{%- endif -%}
		{%- endfor -%}

I am bit unaware of this. that is getting data inside HTML.
Many HTML file includes data from py file.
Can anybody make me know from where this ‘post_login’ data in the for loop comes? What is the corresponding .py file for this .html file?

def post_login(self):

it comes from

Thank you…

So when we create a custom HTML file and want to get some data from database what can i do?
Is it enough that I should create a py file with the same name? Then I get the values of the variable in py to HTML file?

can you please make me know?

Whenever DocType is created .py .js and .json created in docType folder. you can use jinja template to render data into html from python file.

you can use this link for reference:

Vishal Dhayagude


I have not created any DocType… I am talking about a simple HTML file creation and showing data there. So my doubt is to from where we get data.? No .json file.

Can you help me in getting this?


It is not from’s post_login function.

I have found the post_login dictionary is defined in
Please check it.

Is there a way to get data from a form in simple HTML file to store in database.?

Not directly from Python. You can use an HTML template and pass it information via JS. I am working on a solution to this currently for a custom app.

Thanks for your reply but I guess you helped the other way. I want to transfer data from HTML form to python.

@royprotim Gotcha. I’m also working on this bit now with the help of the MN Technique team. I can get you as far as the collecting the client side form JS variables, but I haven’t gotten farther than that.

@revant_one @gvrvnk I meant to bring this up on our most recent call and it totally escaped me. I assume it’s some sort of callback?

html is accessible with jquery using .find()
first render template into wrapper.
then use .find() on that wrapper

It is recommended to use Custom Dialog to get inputs as it has docfields. Refer example. It has button for “Log Visit” which adds new_doc with quick entry or custom dialog.

refer last section of following for Custom Dialog :

Note: in the above example call_allocations_html template renders only latest five and adds a view all button which set_route to normal Frappe list view.

1 Like