Python and Django pointers – Part 1: Using Virtualenv and Context Syntax

So I’ve decided to try (again) to learn how to code a full Web Application in Python using Django as the framework.

The number of false starts in my endeavour is enough to make me discouraged, but I just can’t totally let it go and I seem to keep coming back to it. Somehow, the desire to actually build something is still there, and I’m just hoping that this time I get somewhere. I’m blogging this experience in part to keep myself in check, and to also document some of my learnings so that I can always come back to it.

I would’ve loved to be coding on a MacBook, but I don’t have one and until I reach a stage where it would be more productive for me to get one, it would make more sense for me to continue using the existing Windows based laptops I have.

First, a few things I’ve (re)learned:

  1. Use pip to install virtualenv in Windows Subsystem for Linux (WSL or Windows Bash). Using Virtual Environment to manage Python Environments and versions are essential to making sure your development environment is consistent. It should essentially be part of your workflow.
  2. Context syntax for multiple variables is as follows: { ‘var_name’: ‘value’, ‘var_name2’: var}
  3. Context syntax for dictionary is as follows: {‘dictionary_name’: {‘var_name’: ‘value’}}
  4. Use “django.shortcuts import render” and then “return render(request, ‘template.html’, {‘context’: bar})”

Ok that’s about as far as I got. Considering it’s only a few hours in, with so much more to go, I really needed to put this down so I can make sure I keep going. At least it’s a start.

Next step is Apps and Migrations within a Project.