loading...
Cover image for New Project, Who Dis? - Building SaaS #38

New Project, Who Dis? - Building SaaS #38

mblayman profile image Matt Layman Originally published at mattlayman.com ・3 min read

Building SaaS (48 Part Series)

1) Building SaaS with Python and Django #1 2) Reporting scraped data - Building SaaS #2 3 ... 46 3) Multiple Stripe plans - Building SaaS #3 4) Using a background scheduler - Building SaaS #4 5) Updating data models - Building SaaS #5 6) Third party integration modeling - Building SaaS #6 7) Displaying third party data - Building SaaS #7 8) Connecting third party services - Building SaaS #8 9) Finishing third party integration - Building SaaS #9 10) Admin dashboards - Building SaaS #10 11) Semi-automated tasks - Building SaaS #11 12) Automation aides - Building SaaS #12 13) Deploying with Ansible - Building SaaS #13 14) Ansible Cranked to 11 - Building SaaS #14 15) Feature Flags with Django Waffle - Building SaaS #15 16) Feature Flags in Action - Building SaaS #16 17) Canceling Stripe Subscriptions - Building SaaS #17 18) Completing Account Deactivation - Building SaaS #18 19) Pip-tools and App Packaging - Building SaaS #19 20) Making a Shiv App - Building SaaS #20 21) Shiv zipapps and CI - Building SaaS #21 22) Upload to S3 with CircleCI orbs - Building SaaS #22 23) It's Alive! A Django Shiv app - Building SaaS #23 24) In the Guts of a Shiv App - Building SaaS #24 25) It's Permissions, Dummy! - Building SaaS #25 26) Connecting Shiv Apps with Ansible - Building SaaS #26 27) Plug the Shiv App Into Nginx - Building SaaS #27 28) Webpack and collectstatic in CI - Building SaaS #28 29) Add Static Assets to Deployment - Building SaaS #29 30) Ripping Out Node.js - Building SaaS #30 31) Celery In A Shiv App - Building SaaS #31 32) wal-e Postgres Backups - Building SaaS #32 33) Get Out, Git! - Building SaaS #33 34) Bring in the WhiteNoise, Bring in Da Funk - Building SaaS #34 35) Deploying WhiteNoise - Building SaaS #35 36) Configurama - Building SaaS #36 37) Lessons From A Failed SaaS - Building SaaS #37 38) New Project, Who Dis? - Building SaaS #38 39) django-environ and django-debug-toolbar - Building SaaS #39 40) Make A Custom User Model - Building SaaS #40 41) User Accounts With django-allauth - Building SaaS #41 42) Add Styles To Templates - Building SaaS #42 43) Use Tailwind On A Template - Building SaaS #43 44) Fast Forms With UpdateView - Building SaaS #44 45) Templates and Logic - Building SaaS #45 46) A Week At A Time - Building SaaS #46 47) How To Style Sign Up - Building SaaS #47 48) Onboarding - Building SaaS #48

In this episode, we started a brand new project! I had some internet troubles so this "stream" is actually a local recording from my computer. We created a new Django project from scratch and set up Heroku to handle deployments.

In spite of the streaming trouble, we were able to get a bunch done. We started the project from scratch so we made a repository on GitHub with some .gitignore settings tailored for Python projects.

The first step in the process was to get a tool to help manage packages. I chose pip-tools to make this process easier. After creating a virtual environment with:

$ python3 -m venv venv
$ source venv/bin/activate

I added pip-tools to a requirements-dev.txt file and installed it.

(venv) $ pip install -r requirements-dev.txt

Then we put Django into requirements.in (with Django 3.0, yay!) and let pip-tools generate our requirements.txt file.

(venv) $ pip-compile --output-file requirements.txt requirements.in

Finally, we installed Django.

(venv) $ pip install -r requirements.txt

This process might seem roundabout, but it will ensure that we have exactly the packages we expect as we make future updates.

I took some time to explain some naming conventions and places where we have choice in the structure of our projects. Ultimately, I picked the name of project to store my settings and WSGI files. To do that, I used django-admin.

(venv) $ django-admin startproject project .

Note the period at the end of that command! It's important.

The next step was to fire up the site and check it out.

(venv) $ ./manage.py runserver

Not much there yet, but it was a start. I added all of this to source control as a checkpoint before we moved on.

For this project, I'm using Heroku as a Platform as a Service (PaaS) to host my application. Prior to the stream, I followed the Heroku tutorial and set up the command line tools.

To try to run Django locally with Heroku's tools, I ran:

(venv) $ heroku local

This failed because the project was missing a Profile. So, we created a Profile to run the app with this line (and added an installation of gunicorn into our virtual environment).

web: gunicorn project.wsgi --log-file -

Now heroku local would start, but we immediately hit an error because of the http://0.0.0.0:5000 URL (which is the default for gunicorn). The failure is that the gunicorn default URL is not in the ALLOWED_HOSTS setting.

Instead of changing ALLOWED_HOSTS, I installed the django-heroku package and added the following to the settings file.

import django_heroku
django_heroku.settings(locals())

This amount of work tweaks the settings to make Django cooperate with Heroku better. We then verified that heroku local worked and were ready to deploy online.

Deploying an app to Heroku for the first time is done in two command. Two commands! That's amazing!

(venv) $ heroku create
(venv) $ git push heroku master

The final result made it to Heroku on a randomly assigned domain name. We successfully deployed an awesome web framework on the internet in under an hour (with me explaining everything along the way).

That's great progress, but there is a lot of work left to do to make the site ready for general use! On the next stream, we'll add django-allauth to make it painless for users to sign up on the site.

This article first appeared on mattlayman.com.

Building SaaS (48 Part Series)

1) Building SaaS with Python and Django #1 2) Reporting scraped data - Building SaaS #2 3 ... 46 3) Multiple Stripe plans - Building SaaS #3 4) Using a background scheduler - Building SaaS #4 5) Updating data models - Building SaaS #5 6) Third party integration modeling - Building SaaS #6 7) Displaying third party data - Building SaaS #7 8) Connecting third party services - Building SaaS #8 9) Finishing third party integration - Building SaaS #9 10) Admin dashboards - Building SaaS #10 11) Semi-automated tasks - Building SaaS #11 12) Automation aides - Building SaaS #12 13) Deploying with Ansible - Building SaaS #13 14) Ansible Cranked to 11 - Building SaaS #14 15) Feature Flags with Django Waffle - Building SaaS #15 16) Feature Flags in Action - Building SaaS #16 17) Canceling Stripe Subscriptions - Building SaaS #17 18) Completing Account Deactivation - Building SaaS #18 19) Pip-tools and App Packaging - Building SaaS #19 20) Making a Shiv App - Building SaaS #20 21) Shiv zipapps and CI - Building SaaS #21 22) Upload to S3 with CircleCI orbs - Building SaaS #22 23) It's Alive! A Django Shiv app - Building SaaS #23 24) In the Guts of a Shiv App - Building SaaS #24 25) It's Permissions, Dummy! - Building SaaS #25 26) Connecting Shiv Apps with Ansible - Building SaaS #26 27) Plug the Shiv App Into Nginx - Building SaaS #27 28) Webpack and collectstatic in CI - Building SaaS #28 29) Add Static Assets to Deployment - Building SaaS #29 30) Ripping Out Node.js - Building SaaS #30 31) Celery In A Shiv App - Building SaaS #31 32) wal-e Postgres Backups - Building SaaS #32 33) Get Out, Git! - Building SaaS #33 34) Bring in the WhiteNoise, Bring in Da Funk - Building SaaS #34 35) Deploying WhiteNoise - Building SaaS #35 36) Configurama - Building SaaS #36 37) Lessons From A Failed SaaS - Building SaaS #37 38) New Project, Who Dis? - Building SaaS #38 39) django-environ and django-debug-toolbar - Building SaaS #39 40) Make A Custom User Model - Building SaaS #40 41) User Accounts With django-allauth - Building SaaS #41 42) Add Styles To Templates - Building SaaS #42 43) Use Tailwind On A Template - Building SaaS #43 44) Fast Forms With UpdateView - Building SaaS #44 45) Templates and Logic - Building SaaS #45 46) A Week At A Time - Building SaaS #46 47) How To Style Sign Up - Building SaaS #47 48) Onboarding - Building SaaS #48

Posted on Apr 30 by:

mblayman profile

Matt Layman

@mblayman

Matt Layman is a software engineer from Frederick, MD. He is an open source software maintainer and advocate for Python.

Discussion

markdown guide