So I had some trouble with the DNS from Cloudflare. First I pointed the www name to my web app and then the "domainname.com" name to redirect to "www.domainname.com". I think that was the wrong approach, but it was something I had done previously on Heroku and seemed to work.
Now, this setup didn't work and I could visit the "www" page, but not the naked domain page ("@"). I tried switching them around and pointing "www" to "@" and changed my pythonanywhere to "domainname.com", which resulted in "domainname.com" being resolved and not "www.domainname.com"
So, finally, I have only 1 name "www" pointing to the web app.
The problem is that, now, when I visit "www.domainname.com", I get redirected to "www.domainname.com/www.domainname.com/" (wtf).
Also I defined a page rule that redirects from "https://domainname.com/*" to "https://www.domainname.com/$1" like this page suggests https://support.cloudflare.com/hc/en-us/articles/224509547
I though that might be the problem but I turned off the rule and it still happens.
Why is that happening and how can I fix it? Seems like a weird error.