Yawd website

Articles Tagged python

  1. The impact of Django page redirects to SEO - Fixing internationalized pattern URLs

    Django makes heavy use of page redirects to handle form submissions, manage multilingual content and accomplish many other tasks. While there's nothing wrong with that (in fact in most cases it is considered to be the best practice), careless use of page redirects might affect our website's page rank. To better understand the potential danger we should first see how redirect works and which tools does Django provide for redirecting to a new page. We will also examine & fix a case where Django does not use the optimal redirect type: the internationalized URL patterns.
    Posted on October 4th, 2012 by Pantelis Petridis
  2. How to keep your django project settings organized

    I like to keep my code organized. One of the issues I came across when exploring django coding is the 'settings mess'. Django settings are loaded on a project -and not application- basis. Having a single python module to define settings for a ton of applications is at least frustrating. When looking for a solution to this problem I found this blog post which cleared my head.

    Posted on October 9th, 2011 by Pantelis Petridis
  3. Using class-based views to process a django form through ajax

    Field-specific errors with the JSONFormView class-based view Since Django 1.3 class-based views have been introduced to allow for code reusability. Class-based views have been criticized for their poor documentation (count me in) and their amazing ability to grow our code size instead of reducing it! The latter appears to be true only if we are not careful with sub-classing. On the other hand class-based views finally deliver django what has been missing: a consistent way of coding all your models, forms and views.
    Unfortunately, django's generic class-based views do not provide a mechanism for implementing JSON views. Ajax requests are the standard way of doing things these days and I feel that django needs some work towards this direction. However, the official documentation offers the implementation of a simple JSONResponseMixin that we will use as a base for our own view. What we try to achieve here is create a view that will process a form, return the errors when the form is not valid or save the form and return a success message otherwise. This is a fairly common scenario and extremely useful when a full page reload is not acceptable (e.g. a newsletter subscription form).
    Posted on August 30th, 2011 by Pantelis Petridis
  4. How to add sitemap functionality in websites powered by django-articles

    Django-articles is an open-source blogging engine written in django. Unfortunately it does not offer a sitemap mechanism and since the yawd blog uses django-articles I had to implement it. If you have a django-articles powered website and want to add a sitemap here is how to do it:

    Download the sitemaps.py file attached to this article and place it under your project's main application. This module uses django's built-in sitemaps framework to define a...

    Posted on June 30th, 2011 by Pantelis Petridis
  5. Using Aptana Studio 3 IDE for django applications - a "Hello world" tutorial

    Aptana Studio 3 is a development IDE targeting the most to web developers. Being an Eclipse-based platform, it runs as standalone application -it utilizes the Eclipse RCP framework-, as well as a plugin inside your existing Eclipse installation. I recently have decided to test Aptana for developing Django applications and this article covers Aptana's basic functionality.

    Installation

    First of all we need to install Python. Python 3 was recently released, but version 3 is not supported by Django...

    Posted on May 31st, 2011 by Pantelis Petridis
  6. Admin widget for generic relations in django

    The contenttypes framework adds wonderful functionality for dynamic foreign keys in Django. However, it lacks of a widget to allow the user select the content object from the administrator website. This article explains how to implement such a widget and embed it to your django-powered project.

    Posted on May 26th, 2011 by Pantelis Petridis
  7. Using signals to generate a decoupled tree-menu application in django

    Although there exist several django menu applications -the excellent django-treemenus is one of them-, they all require that the user explicitly sets the menu structure. Consider the following scenario in a django CMS application: The user will probably be able to define a list of article categories -and sub-categories- and will also write a bunch of articles tied to each one of these categories. At the same time, this hypothetical user would also be able to use a blogging engine and publish his thoughts. Let's assume that the user wants to add an article category to the menu and use its sub-categories as sub-menuitems. He also wants to add a link to the blog main page and use the most popular tags as sub-menuitems. To accomplish this he must manually define a menuitem for each menu link and map it to the corresponding url, which is less than ideal. In this article, we will demonstrate a menu application that would enable the user to define a top-level item -e.g. an article category- and optionally have all children items automatically inherited from the corresponding parent element.

    Posted on May 20th, 2011 by Pantelis Petridis