Django-allauth Installation

There is a useful django-allauth video tutorial at Create third party Facebook login in Django. The document below simply follows that but only adds facebook social authentication. Documentation can be found at django-alluth documentation. django-allauth can also be installed by cloning from I am running Django 1.9.5 and will install django-allauth 0.25.2 Setup a…Read More

Part 6: Django CRUD, Update

Continued from Part 5: Django CRUD, Delete Full code on We may wish to update the model ‘Members’. Let us start by adding an edit icon to the table in ‘index.html’. <td><a href=”{% url ‘edit_new’ %}”><span class=”glyphicon glyphicon-pencil”></span></a></td> If you are not using Bootstrap replace the span tags with ‘edit’. <td><a href=”{% url ‘edit_new’…Read More

Part 3: Django CRUD, Display Models

Continued from Part 2: Setting up Django, URL’s & Views Full code on Add to the crudapp/ file from django.db import models In the same file create a model called ‘Members’ with columns for ‘first_name’, ‘last_name’ and ‘description’. This is equivalent to a table called ‘Members’ with fields for ‘first_name’, ‘last_name’ and ‘description’. class Members(models.Model): first_name =…Read More

Simple Python into HTML

The following Python code will find instances of {body} in a file template.html and replace it with a string. Then a new file index.html is created with this change. with open(‘template.html’,’r’) as template_file: template = content = template tokens = {‘body’: ‘Body stuff can go here’} replaced = ‘Body stuff can go here.’…Read More

Running Python unittests from Command Line

This script will allow a Python unittest to be run from the command line. import unittest import testFile suite = unittest.TestLoader().loadTestsFromModule(testFile) unittest.TextTestRunner().run(suite) import unittest from fun import add class test_function(unittest.TestCase): def test_one(self): result = add(2,3) self.assertEquals(result, 5) def add(a,b): return a+b

Simple Python Unit Test

This simple Python unit-test tests two function. The first function adds two numbers and the second function uses list comprehensions to make a list of numbers from to 0 to n which are divisible by m. import unittest from add import addition, make_list class test_add_function(unittest.TestCase): def test_for_add(self): result = addition(1, 5) self.assertEqual(result, 6) def…Read More