Displaying Ads on Python Flask Sites 🐍

How come Google AdSense is not detecting my ads.txt file? πŸ“

tl;dr Needs a route.

AdSense πŸͺ§

βœ… You've signed up for AdSense
βœ… AdSense has approved your site
❌ AdSense is not detecting your ads.txt file


Showing my Age πŸ’½

The AdSense instructions state to put the ads.txt file in the root of your sites filesystem. So, me thinking of the old bare metal 🀘 days puts it there, but AdSense can't find it. Well the bare metal days are gone and this is a flask app, in Docker containers, behind a proxy, and a load balancer; phew πŸ˜….

Create a Route β¨’

The solution is to create a route in your flask app that serves the ads.txt file.

1
2
3
@app.route("/ads.txt")
def serve_ads_txt():
    return send_from_directory(app.static_folder, 'ads.txt')

Then place the ads.txt file in the static/ directory of your flask app.

Success 🎊

Now AdSense can find the ads.txt βœ…. Once you know you know. Have fun out there on the internet folks. πŸ•ΈοΈ

πŸ“¨ Contact GSPC βœ‰οΈ

ITIL 4 Foundation Certified AWS Certified Cloud Practitioner Certified Terraform Associate AWS Serverless AWS Certified Developer Associate GitHub Foundations Certification GitHub Actions Certification Certified SysOps Administrator Certified AWS Security Specialist Certified AWS DevOps Engineer Professional GCP: Cloud Digital Leader Certification Badge Solutions Architect Associate Solutions Architect Professional Certified AWS AI Practitioner