A few months ago I started my journey to build my first web app, Rental Tensor (excuse the horrible name 😎) in order to estimate the rents for different properties at the zip code level. As a trained statistician disguised as a techy Data Scientist, I love playing with a mix of code and data, but I feel that it can sometimes be difficult for models or data pipelines to be very valuable without some sort of web backbone to host and serve it. As the old proverb says: “a great model stuck on your hard drive is just some code”. While I am familiar with Shiny which can be used to serve models to real users via a web format (without leaving R!), I felt like it was time for me to learn how to host a more robust and flexible service.
Now that I removed 90% of my options, I only had to choose between two options: Flask and Django. Since the consensus of random people on the internet seemed to be that ‘Django makes more decisions for you than Flask’ I decided to try to learn Django since I’m not a web developer and don’t want to make every decision I might be tempted to make. It might be strange, since almost all blog posts I read a super opinionated - but I felt very comfortable picking either framework and have no idea what I gained or lost by picking Django over Flask. That being said, I’m super glad I didn’t need to learn a whole new language just to build something cool.
Learning Django (enough to put together something somewhat functional) consisted of following along three tutorials before hacking away: the classic Django Polls tutorial, Tango with Django, and Django for Beginners.
The Django Polls tutorial was a great introduction that opened my mind to what was possible with Django. You take a concept (a website where people can vote on questions) and slowly build the parts needed to turn it into a real working website. It really shepherds you through the basic concepts and even shows you some of the internal mechanics that power the Django model/database framework (using interactive SQL) - very cool! This tutorial trades off some completeness in order to be concise and easy to follow, but I definitely recommend this canonical starting place for beginners. Plus it’s free!
Django for Beginners was pretty neat as it was a collection of several small projects that you build from scratch. While much of the material was actually covered in the previous two resources, this book really solidified some key concepts for me and got me feeling more comfortable in the Django environment.
My first project
I wanted to make a dynamic calculator that would estimate the rent for a property via scraping real rental listings given a set of property parameters such as location and number of bathrooms. I figured this would be good first project as it was simple (the web app only does one thing - estimate rents), dynamic (we are computing estimated rents on the fly), and the application would scrape rental listings from the web (This wasn’t something I had known how to do before). After building a web scraper using Beautiful Soup I slid it into a Django view and voilà! - I have a working app!
The most difficult hurdles past this point was creating a query string so one could share their results with just a URL, and hosting the web app effectively. The query string issue was something I hadn’t thought about before, but it seems very important for as much information as possible to be captured in the
While I’m excited to have completed my first semi-functional web app, I’m even more glad I have the confidence now to try different things and to incorporate some of my data experience into apps that will hopefully help others.