pythonmako

How to write urls in mako python


Hello there thanks for helping me,

I have some file.mako.md file and I am changing this file as shown below but it shows me 404 error which is due to it takes wrong url address ie it takes url like https://stackoverflow.com/questions/ask" rather than https://stackoverflow.com/questions/ask and due to which gives server error, any help will be appreciated

<%!
  import requests
   
  def build_path_with_dataset_name(ds_name):
    github_path = "https://github.com/Eshan-Agarwal/datasets/tree/patch-58/docs/catalog/images/" + ds_name + ".jpg"
    return github_path
  
  def example_exists(path):
    r = requests.head(path)
    return r.status_code == 302 
%>

it reads url https://github.com/Eshan-Agarwal/datasets/tree/patch-58/docs/catalog/images/" gives 404 error see this image

EDIT : I think this is due to underline appear on can anybody know how can we remove it


Solution

  • Have you tried with a f-string?

    import requests
    
    def build_path_with_dataset_name(ds_name):
        github_path = f"https://github.com/Eshan-Agarwal/datasets/tree/patch-58/docs/catalog/images/{ds_name}.jpg"
        return github_path
    
    def example_exists(path):
        r = requests.head(path)
        return r.is_redirect
    
    dataset_name = 'mnist'
    path = build_path_with_dataset_name(dataset_name)
    print(example_exists(path))