[SOLVED] Insert a record on doctype when Web Page loads

So, I have this function:

def activities_log(_type=None, item_searched=None, product_seen=None, product_from=None, search_from=None):
    doc = {
        'doctype': 'Store Logs and Activities',
        'user': 'dsds'
    logs = frappe.get_doc(doc)
    return '1'

I want this function to insert a new record on doctype every time a page loads. I am implementing like this:

def get_context(context):
    context.ttt = activities_log(_type='Home Page')

It returns 1 but does not insert new data on doctype.

Found the solution. Look like on page load the request is GET while I was trying to POST. So I created another function:

def a():
    import requests

    session = requests.session()

And it worked.

P.S. If you have better suggestion, feel free to post the answer.

1 Like