Posts about Django

Avatar for vbabiy@howsthe.com

Python mocking with mox

Published Jan. 10, 2010 by Vitaly Babiy

When building an application it's hard not to depend on some outside resource, that you have no control over. When writing unit tests for this type of application it gets tricky, but thanks to mocking you are able to do so. Mocking comes in two forms, manual (a.k.a monkey patching) or using a mocking framework, we will be using the latter. A mocking framework creates objects that add expectations, define their methods, and return values for each method call in a simple way.

There are a few mocking frameworks available for python:

Avatar for vbabiy@howsthe.com

Django Testing

Published Jan. 4, 2010 by Vitaly Babiy

Test driven development will help in a few aspects when developing an application. One aspect is you get to eat your own dog food even before you make it. You are able to use your API's before they are implemented, this will display any short comings in the design. Also by forcing yourself to think through a problem and get a better understanding, which in turn helps make better design decisions. We all make mistakes, without testing our code base there is no way to be sure that everything is still working, otherwise you are crossing your fingers and knocking on wood.

Django and Python Test Tools

If you've been using Django for some time you have heard the phrase "Django is just Python" and this holds true in the realm of testing your Django Application. You can use other testing frameworks with Django like nose. Django comes with a good testing framework that is built off the Python unittest module. The default Django testcase is a subclass of unittest.TestCase this class provides with some additional assertions and also a client that will helps you test your views ( more details to come ).

Avatar for vbabiy@howsthe.com

Django with nginx, mod_wsgi, and SSL

Published Sept. 20, 2009 by Vitaly Babiy

Howsthe.com has made an architectural change in our deployment stack. We were using mod_wsgi and Apache to serve the static content, which was not working as well as planned. We moved to using nginx as a front end proxy and a static content server. It also acts as a gateway for the SSL connection so we don't have to run different mod_wsgi instances for HTTP connections and for HTTPS connections. Below we explain how we configured this setup.

Prerequisites:

We'll be using Ubuntu 9.04 server, the following packages need to be installed:

  • apache2
  • libapache2-mod-wsgi
  • nginx
  • subversion ( Only if you are going to install Django from SVN )

This doesn't include database installation, for this example we will not be using a database. If your application uses a database, install the correct python drivers and make sure your settings.py file is configured correctly.

Once these packages are installed, then install Django. We will not be going over this here due to expediency. You can find the directions at http://docs.djangoproject.com/en/dev/intro/install/.

Avatar for vbabiy@howsthe.com

12 Tips to Better SEO

Published Sept. 15, 2009 by Vitaly Babiy

Advertising is very expensive, studies have shown that it is not as effective as being on the first page of search results. These SEO tips will help you rank higher on the search engines results, and who doesn't like free referrals.

  1. Content is King
    Search engines want something to index. If your website doesn't have much content the search engine will not rank you as higher authority for these keywords. Also it gives other websites the opportunity to link to you. For instance if you have a blog, this can generate many links to your website. These links will allow the page rank to flow, the more links to your website the sooner it will be indexed and more often.

  2. SEO Friendly URLs
    URLs that use query parameters to get a website like http://www.howsthe.com/blog?id=100, have nothing in the URL that describes what the website is about. On the other hand a URL similar to http://www.howsthe.com/blog/12-seo-tips-for-beginners/ gives a brief description of the content on the page.
    It's important to optimize your website for keywords that match what your user base is searching for. Using URLs with less query parameters allows these keywords to be placed within the URL.

A blog about development, marketing, and design.