PythonAnywhere and CloudFlare

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, which is one of the domains we have lying around.

The setup of a website on CloudFlare is pretty straightforward. If you give CloudFlare your domain, it automatically interrogates the DNS system for the domain’s current settings and provides excellent instructions about what needs to be changed. You will see something like this afterwards (unless you they changed their interface :)

screenshot of cloudflare dns settings page

Now, you just need to set up a simple CNAME record for your PythonAnywhere web app. Assuming you’ve already created a web app on PythonAnywhere like this:

Screenshot of web app creation

From the web app config tab you’ll have a CNAME target for your PythonAnywhere web app – something like “”.

On the CloudFlare DNS config screen, create a CNAME for the “www” subdomain to point at this web app. That’s all you need to do to get your site working!

Either way, now when we go to, 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: Screenshot of dynamic response headers

and these are the response headers for a static resource on that page: Screenshot of static response headers

If you’re a complete-ist and you want to get the naked domain working (that is, instead of, you need something a bit more complicated called a “page rule”. Check the cloudflare documentation, essentially you’ll want to point* to$1.

comments powered by Disqus