python-3.xcookiesfasthtml

How to delete a cookie in FastHTML?


I want to delete a cookie (for instance "cookie1") in the endpoint "/delete_cookie1"

import fasthtml as fh

@app.get("/delete_cookie1")
def delete_cookie1(request):
    my_delete_cookie_function(request,'cookie1') # ?????????

Any help? Thanks


Solution

  • Thanks to the comment from @mr-mcwolf , setting the parameter max_age=0, the cookie "cookie1" can be removed as follows:

    from fasthtml import common as fh 
    app = fh.FastHTML
    
    @app.get("/removecookie1")
    def getdbpools(req):
        return fh.cookie(key='cookie1', value='', max_age=0)