A beginner's guide to building a simple database-backed Flask website on PythonAnywhere: part 2

Welcome to the second part in our tutorial for getting started with Flask development on PythonAnywhere! This is a continuation of our previous tutorial, so if you haven’t been through it, you should do that first. In particular, this tutorial will assume that you’re starting with the code that you had at the end of the last one: a simple website that allowed you to post comments on a page, all of those comments being stored in a database:

It was made up of two files; a Python file which controlled what it did, and a template file that controlled how it was displayed. All of our code was under source-code control, and it was running as a website on PythonAnywhere.

Obviously this was a rather limited website! It would be nice if we could add some features – and in this tutorial, that’s exactly what we’ll do. Our original site used the slightly ugly password protection built in to PythonAnywhere; this means that in order for people to post on it, they had to enter a username and password – but it was the same username and password for everyone, which isn’t terribly secure. We’re going to add our own login page – which means that we can also store a record of who posted what, and when.

Here’s what it will look like:

Adding these new features will require us to do a bit of work in the background; our existing site works fine for what it is, but it’s not very extensible, and we’ll fix that as we go. You’ll learn about the Flask-Login extension, database migrations, and virtualenvs – all very useful stuff.

Let’s get started!

Read more…

The PythonAnywhere newsletter, September 2017

Gosh, and we were doing so well. After managing a record seven of our “monthly” newsletters back in 2016, it’s mid-September and we haven’t sent a single one so far this year :-( Well, better late than never! Let’s see what’s been going on.

Read more…

Outage report: 20, 21 and 22 July 2017

We had several outages over the last few days. The problem appears to be fixed now, but investigations into the underlying cause are still underway. This post is a summary of what happened, and what we know so far. Once we’ve got a better understanding of the issue, we’ll post more.

It’s worth saying at the outset that while the problems related to the way we manage our users’ files, those files themselves were always safe. While availability problems are clearly a big issue, we regard data integrity as more important.

Read more…

Using the PythonAnywhere API: an (open source) helper script to create a Django webapp with a virtualenv

With the beta launch of our API, we want to start making it possible for people to do more scripted things with PythonAnywhere.

Our starter for 10 was this: our web-based UI has some helpers for creating new web apps for common web frameworks (Django, Flask, web2py, etc), but they pin you to the system-installed version of those packages. Using a virtualenv would give the user more flexibility, but currently that means using the more complicated “manual config” option.

The API means it’s now possible to build a single command-line tool that you can run from a PythonAnywhere console to create, from scratch, a new Django project, with a virtualenv, all in one go.

Read more…

The PythonAnywhere API: beta now available for all users

We’ve been slowly developing an API for PythonAnywhere, and we’ve now enabled it so that all users can try it out if they wish. Head over to your accounts page and find the “API Token” tab to get started.

The API is still very much in beta, and it’s by no means complete! We’ve started out with a few endpoints that we thought we ourselves would find useful, and some that we needed internally.

Read more…

System update this morning

This morning’s system update went well :-)

There aren’t any major visible new features in the new system – it was primarily an infrastructural change. The operating system on our underlying servers has been upgraded from Ubuntu 14.04 to 16.04 (so we had to rewrite all of our upstart system jobs as systemd ones, which was… fun). The sandboxes where your code runs have been kept as Ubuntu 14.04, so that your code doesn’t break due to the system it runs on changing unexpectedly.

A future update, hopefully soon, will enable a 16.04-based system image that you’ll be able to opt in to use when it’s convenient to you. There’s also a big new feature that we’re working on that required the OS upgrade – more about that another time…

Read more…

Tomorrow's system update cancelled

At the last minute, we discovered a bug in the version of PythonAnywhere we were planning to deploy tomorrow. We’re pretty certain about the fix, but rather than rush code into the live system without thorough testing, we’re delaying the system update. We hope it’ll all be ready to go early next week.

New release! Python 3.6 :-)

Today’s system update was mostly infrastructure changes and security fixes, but there’s one big visible change – we now support Python 3.6!

The new version is only available for accounts using the new dangermouse image, so if you’d like to be switched over and get not just the latest Python, but also new shiny versions of all of our installed system images, just send us a message using the “Send feedback” link.

Blocked in Russia

A week ago, one of the sites we were hosting was reported to us by the Russian authorities (specifically, the Federal Service for Supervision in the Sphere of Telecom, Information Technologies and Mass Communications [ROSKOMNADZOR]) for hosting illegal content. They said that we must take it down, or risk having the associated IP address blocked in Russia.

Read more…

New release! File sharing, and some nice little fixes and improvements

Honestly, it’s strange. We’ll work on a bunch of features, care about them deeply for a few days or weeks, commit them to the CI server, and then when we come to deploy them a little while later, we’ll have almost forgotten about them. Take today, when Glenn and I were discussing writing the blog post for the release

  • “Not much user-visible stuff in this one was there? Just infrastructure I think…”
  • “Let’s have a look. Oh yes, we fixed the ipad text editor. And we did the disable-webapps-on-downgrade thing. Oh yeah, and change-webapp-python-version, people have been asking for that. Oh, wow, and shared files! I’d almost totally forgotten!”

So actually, dear users, lots of nice things to show you.

Read more…