OK, so I won’t be doing blog posts as often as I thought – I’ve had a lot of other non-technical things going on. However, I have dug back into Django again – and I’ve fallen in love it all over again!
It does seem like it will ultimately be pretty unusable on Windows (due to a list of issues with working with a real RDBMS), it is pretty good on Linux and/or MacOS. I’m working on a project, mostly on Ubuntu, but it runs equally well on MacOS – and I came up with some noteworthy things.
First, since I first dug into this last year – this framework continues to amaze me. The idea is that you can basically define your database tables in a few dozen lines of code, Django will automatically give you Create Read Update Delete (CRUD) screens, with validation, and dropdowns for the related tables – stuff that is tedious and takes time to write. That is referred to as Django Admin. PLUS the Django Rest Framework with just a few lines of code per table will expose REST endpoints for each table, AND give you a website where you can learn and play with the REST API.
In short, I’m nothing short of blown-away by this technology. I’ve never seen anything like it. Needless to say, I’m planning to and am actively working on a project that uses this. I’m most excited that this will save me 10’s of thousands of lines of code I’d otherwise have to write in .NET – if I were to use that technology instead!
Wait a second, if this isn’t a great idea on Windows, how am I writing code? What am I using for an editor? I’ve said it once and I’ll say it again, Visual Studio Code, the standalone code editor is an amazing tool. Not only is it amazing editor, but it runs on Debian or Fedora-based Linux distributions (*.deb or *.rpm) and it runs nicely on MacOS too.
So, for Django, I installed VS Code on Ubuntu, installed the Python extensions to give me color-coding and intellisense, and it’s been a dream to work on! Not only is is a great editor with all of the “comforts” I normally need from Visual Studio working with .NET code, it also seamlessly has Git functionality built right in too!
Meanwhile, for Django stuff, I have a split console using “tmux”.
On the bottom is “manage.py runserver” which runs the web server, and automagically restarts whenever it detects a code change – and will give me compile errors upon changes too. On the top is a console in that Python environment where I can make and push database migrations. These are just like Entity Framework migrations, except you do them from the command-line:
So – this ends up being a nice little development setup. It’s very quick, and since Django does SOOOOO much for you, you can stand up an application in a very short amount of time.
Since this is a proprietary/for-profit app, I’m using VSO for it instead of GitHub. So, I created a new Git repository. There are a couple of things which took a little bit to figure out. One is if you have two-factor authentication turned-on for your Microsoft account (which you definitely should), you can’t use those credentials from the Git command-line. Luckily, Git providers like GitHub and VSO give you a way to supply alternate credentials. In the case of VSO, it’s here:
But you’ll see a message on there that this is highly discouraged. instead, you should create “personal access tokens”. You can do that from here:
How do you put all of this together? Well, to get started with Git – check out this blog post. The only thing that is different is that when you go to do a “git push” or “git pull”, you will be prompted for credentials. How this “personal access token” works, is that you can put anything in the username field (or leave it blank) and you use the access token for the password. OK, that one is easy.
However, the next thing I found is that 1) I needed to register with Git and tell it who I was and 2) it prompted me for credentials every-single-time, which got annoying. So, to register your credentials and cache them, do something like this from the command-line:
$ git config –global user.name “John Doe”
$ git config –global user.email “email@example.com”
and then to enable a credential cache, do something like this:
$ git config –global credential.helper cache
$ git config –global credential.helper ‘cache –timeout=3600’
Where that timeout is in seconds.
Once all of that is in place, development was easy-breezy! I save changes in VS Code, the Python web server restarts and I can see my changes in the website. When I’m done working, I use VS Code to “Sync” where it commits my changes, pushes them to VSO, then does a pull from VSO – making it so my local machine is N’Sync with VSO.
I know there are selling-points to other technologies, but I will say, I’m more-than-pleased with everything I’ve done in Django so far. Aside from the Windows RDBMS issues, I haven’t run across anything else really which has slowed me down! So, if you are wondering how to work with Django on Linux or MacOS, and use Git as a source control provider, hopefully this helps!