CloudFlare is a security and acceleration service that sits between your application and the big, bad internet. Here's how to get all that goodness for your PythonAnywhere web app.
Since CloudFlare works by taking over the DNS configuration for a site, this will only work for custom domains. I have used minimumviableserver.com, which is one of the domains we have lying around.
The setup of a website on CloudFlare is simplicity itself. CloudFlare interrogates the DNS system for the domain's current settings and provides excellent instructions about what needs to be changed. After following this process, there is only one thing more to be done.
In order to configure CloudFlare so that it serves a web app from PythonAnywhere, the one change that is necessary is to set the "www" CNAME to point to a PythonAnywhere account. With these settings, the naked domain minimumviableserver.com gets redirected to www.minimumviableserver.com.
The CNAME for direct.minimumviableserver.com that you can see in the screenshot is provided by CloudFlare so you can get direct access to your servers without going through CloudFlare (for ssh or ftp, for example). It is not very useful for PythonAnywhere because <username>.pythonanywhere.com is probably a different web app and ssh.pythonanywhere.com is there for direct ssh access.
Once everything's set up on CloudFlare, it's time to create the web app on PythonAnywhere.
So now when we go to www.minimumviableserver.com, we see our web app, but how do we know it's going through CloudFlare? looking at the network logs in our browser's developer tools, we can see that there are plenty of indicators in the response headers.
Here are the response headers for a dynamically generated html page:
and these are the response headers for a static resource on that page: