Setting up the Django Base Template for Website Development

Posted on April 11, 2013 in Blog, Making Stuff, Software Development | 0 comments

I’m trying to expand my technical repertoire by building a website using Python and Django. I’ve been through a couple of Django tutorials and have modeled my data, page design and website user workflow, so there’s not much left to do but get the stuff coded up.

Actually, I started project-specific coding as I worked through the tutorials.  By the time I realized that I needed to use Django Base Template, I’d already gone through two restarts. Restarts are a natural part of learning a new development environment and the practices that surround development in any language. For those who aren’t coders, let me explain a little. Starting development in a new language is more than just learning language syntax. On top of that you have to include the following stack (mouse over the text in the box to see a brief description):

Deployment and Management Tools

Development Tools

Language Add-ons

Style Rules

Language Idiom

If I were to arrive into a company that is already developing applications, they will have defined their preferred stack and would help me understand how to apply it to their standards. Since I’m currently a development team of one, I have to rely on the internet and networking to get the same information. That can wslow an independent developer down.

While searching for information and tools to develop a Python/Django website with Twitter Bootstrap (CSS, HTML and JavaScript framework/templates), I stumbled upon the Django Base Template  that incorporates the work of Mozilla Playdoh  and Two Scoops of Django .

Django Base Template is a project template with a lot of goodies that I probably won’t take advantage of in my first project. It was, after all, created for Mozilla Employees to support a very large set of functionality. At some point I’ll trim it down to what I actually need, but for now more is better.

I’m using Django Base Template for development on a Windows 8 (yeah, it’s as bad as everyone says it is) computer with Bitnami DjangoStack v1.4.4  and virtualenv . I updated the version of Django that comes in DjangoStack from v1.4 to v1.5. I decided a few months ago to use Komodo as my Python editor. I use Programmer’s Notepad  for most other editing purposes, but Komodo seems to have a more tightly integrated set of Python templates. One of the cool things it does is give me real-time feedback on adherence to the PEP 8 programming style guide . I see that Programmer’s Notepad has a Python language add-on now, so maybe I’ll give it a try again.

So I’m installing Django Base Template and suddenly the fun begins. The build process gets to the bcrypt component and spits out an error. Before the installation is complete, I’ve encountered several more errors. Luckily I worked my way through them and may be able to help you do the same. Below, is a set of steps that I used to get it working.

Two small things before diving in: When you see a command line, assume that it has administrator privileges. It’s probably not strictly needed for all steps, but it sure doesn’t hurt. Also, check all italicized strings and replace with your own appropriate strings

  1. Install MinGW for the gcc compiler and some Linux commands that a couple of packages use in their installation. If you already have Microsoft Visual Studio’s C++ compiler installed, you don’t have to use the gcc compiler. Unfortunately, I read that you have to have the “right” version of Visual Studio. The “right” version is the same one that was used to build python.exe. I don’t have Visual Studio installed, so the rest of these instructions assume that you too will be using gcc. If you do want to use Visual Studio, it should be reasonably easy to take out the gcc-isms.
  2. Add the following to your PATH environment variable: “c:\MinGW\bin;C:\MinGW\msys\1.0\bin;C:\MinGW\msys\1.0\sbin
  3. At the command line execute the following: startproject –template –extension py,md,rst yourprojectnamehere 
  4. Uncomment the appropriate database adapter in the file  requirements\compiled.txt. I’m using PostgreSQL, so I uncommented “psycopg2
  5. [If using gcc instead of Visual Studio] Create the file c:\bitnami\Lib\distutil.cfg and add the following lines to it:
  6. [The file location assumes that you're using virtualenv. This is safe to do if you're using either gcc or Visual Studio] In the file c:\users\yourwindowsaccountnamehere\Envs\build\py-bcrypt\bcrypt\bcrypt-python.c replace a single instance of “_MSC_VER” with “_WIN32″
  7. [The file location assumes that you're using virtualenv. This instruction may need to be tweaked for Visual Studio users] In two files, c:\users\yourwindowsaccountnamehere\Envs\build\py-bcrypt\bcrypt\blowfish.c and c:\users\yourwindowsaccountnamehere\Envs\build\py-bcrypt\bcrypt\bcrypt.c , add the following lines just below #include <sys\types.h>
    #include <stdint.h>
        #define u_int32_t uint32_t
        #define u_int16_t uint16_t
        #define u_int8_t uint8_t
  8. [You probably don't need to do this if you're using Cygwin instead of MinGW] Edit c:\Bitnami\djangostack-1.4.4-0\python\Lib\distutils\ to remove all instances of “-mno-cygwin
  9. [You don't need to do this if using VisualStudio] From the command line in the C:\Users\yourwindowsaccountnamehere\Envs\yourprojectnamehere\build\py-bcrypt directory, execute the command:
        python  build –c mingw32
  10. [You don't need to do this if using VisualStudio] From the command line in the C:\Users\yourwindowsaccountnamehere\Envs\yourprojectnamehere\build\pycrypto directory, execute the command :
        python  build –c mingw32
  11. [If you haven't done so already, you need to install pip] From the command line, cd to your project directory and execute the following command:
    pip install -r requirements/local.txt

If all goes well, you won’t see any errors and will be able to get to the actual coding. Good luck!