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 }}" {{ child.target or '' }}
					rel="nofollow">
					{{ child.label }}           <!-- My account, Logout -->
				</a>
			{%- endif -%}
		</li>
		{%- endfor -%}
	</ul>

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):
self.run_trigger(‘on_login’)
self.validate_ip_address()
self.validate_hour()
self.make_session()
self.set_user_info()

it comes from auth.py

@vishdha
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:
http://jinja.pocoo.org/docs/dev/templates/
http://frappe.github.io/frappe/user/en/guides/portal-development/

Regards,
Vishal Dhayagude

@vishdha

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?

@vishdha

It is not from auth.py’s post_login function.

I have found the post_login dictionary is defined in website_settings.py.
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

https://bitbucket.org/mntechnique/b2c_aspa/src/c2174c4f863a7e3f6cb72c0ec5f7287deb2a7978/b2c_aspa/b2c_aspa/doctype/aspa_call/aspa_call.js?at=testing&fileviewer=file-view-default#aspa_call.js-157

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 : https://frappe.github.io/frappe/user/en/guides/app-development/dialogs-types

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