Thursday, May 23, 2013

It really worked!


Chapter 4 of the Django book got off to a poor start when I followed their instructions to run 'python manage.py shell', and unexpectedly got a syntax error from one of the core django files. It seemed unlikely there was an actual issue with the file (didn't I even run it myself yesterday?), and after googling the error one of the results mentioned 'of course, I have python 3' so I remembered that I have python 2 and 3 installed, but the django installation came with python 2. I updated my path and the python 2 executable so I could call 'python2' to get python 2 running, leaving my default of 3 still there, and running under python 2 succeeded.

However this does mean I'll have to check my app, which was written in 3, for compatibility with 2 - at the very least all those print statements will be wrong :/ It also means that I can't run my python programs in Sublime Text because it is in Python 3.
Whoa. Actually the only change I had to make was remove the 'newline' option from csv.reader. Way easier than expected!

Useful introductions in the first half of this chapter: templates and contexts, template variables, accessing lists, dicts, and methods through dots, basic logic tags available in templates, filters, comments. Further details can be found in the appendix, which they recommend you read so as to familiarise yourself with all the available options.

And now part 2 - using a template to create a view.

Step 1 - put the full path to your templates files in the settings file. That's easy enough locally, but I'll have to look up what it will be on azure. For now I guess I can just use os.path of the settings file (prompted by their example) but that might not be where I want it to live.

Step 2 - update the views to call templates. Easy enough.

Step 3 - template inheritance. Awesome!

I followed along with code as they went, creating my own side example of attendee schedules to make sure I was getting it - everything worked as expected, it felt really simple but quite powerful. I committed it all to Azure and that worked straight off as well.

No comments: