Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Mails amb Django - IV
Amb tot el que hem vist fins ara podem organitzar els nostres enviaments de correus i mantenir al seu manteniment organitzat encara que el nombre d'opcions sigui gran. Hi ha encara un grapat d'escenaris que és interessant tractar, ja que ens els trobarem sovint. Pensem en aquests possibles escenaris: Ens hem de connectar a un servidor SMTP extern i el temps de connexió és gran, la qual cosa fa que la nostra aplicació web no respongui. Tenim un entorn de preproducció on els correus no s'enviïn però on volem mantenir registre del que s'hauria enviat. Volem mantenir un registre dels correus que s'envien dins la nostra aplicació. El primer escenari es pot resoldre amb un servidor de correu local y fent realy cap al servidor final, però això a vegades no és possible ja que no tenim la gestió del servidor de correu. També ho podem resoldre amb un sistema de coes, és a dir, l'enviament de correu es posa com a tasca i és un altre programa (un worker) el que se n'encarrega de fer l'enviament. La combinació de Celery+Redis ens pot anar bé, però també estam afegint un factor gran de complexitat: hem de tenir Redis instal·lat, configurar … -
Getting AngularJS Authentication Working with Django
django-angular-auth is a very simple example app or seed to get AngularJS authenticating using Django and Tastypie. Although AngularJS' documentation has gotten much better, it still took me quite a while to figure out what exactly was the best path to take. Also, there are a few gotchas with allowed headers and cross-site security which are already solved in the example. Take a look and let me know what you think. -
Custom Django Template Tag: Generate the absolute URL
Custom Django Template Tag: Generate the absolute URL -
Mails amb Django - III
Fins ara hem vist com podem enviar correus electrònics amb format text, amb format HTML en el dos formats. També hem vist que podem generar el nostres correus a partir de plantilles Django. A poc que l'aplicació es vaig fent més gran veurem que és molt interessant poder tenir tots els correus que enviam centralitzats, de manera que no hagem d'anar a cercar per codi i per les diferents aplicacions els correus que enviam. Sovint a més els correus que enviam són semblants: van dirigits a la mateixa gent, o tenen informació que canvia molt poc d'uns als altres, com el peu del missatges o la salutació. Una situació ideal per utilitzar dues coses: les plantilles de Django per a la generació de correus i aprofitar com Django va a cercar les plantilles per tenir tots els correus centralitzats a un mateix lloc, i per una altra banda l'herència pròpia de Python que ens permetrà guanyar temps a l'hora de generar els correus i farà que siguem menys propensos a error a l'hora de generar-los. Ara és quan a un se li encén la bombeta i es posa com a un boig a generar classes de Python per a la … -
Useful Packages for Django projects (part 1)
This is the first of a series of posts about which libraries and tools we use for our Django development. Almost every Nomadblue project will have the following packages in their requirements.txt pip file. Probably most of the readers won't find much news here; however, eventually someone can realize he was missing something that could be leveraging their productivity or making life easier. Pillow As stated by the library documentation, Pillow is the "friendly" PIL fork by Alex Clark and Contributors. With Pillow you can stay cool as it installs smoothly using pip, and also you can sleep at night because somebody is maintaining the library in a healthy state through continuous integration, regular releases, bug fixing and development on github, and active participation on the Imaging-SIG. South When we started with Django (more than 5 years so far) there were a bunch of migration libraries out there, with different approaches. Andrew Godwin became a frequent flyer on the Django community, eventually winning the pulse and gathering the Djangonauts until South became a "must" or "de-facto" library to manage your database schema and data transitions. Worth mentioning that Andrew recently applied at kickstarter for a call to develop "a new, … -
Django CMS: cannot import name plugin_pool
Django CMS: cannot import name plugin_pool -
Overloading Django Form Fields
One of the patterns we get positive feedback for mentioning in our book is overloading form fields. The problem this pattern handles is the use case of when we have a model with a field(s) that allows for blank values, how do we force users to enter values? For example, assuming the following model: # myapp/models.py from django.db import models class MyModel(models.Model): name = models.CharField(max_length=50, blank=True) age = models.IntegerField(blank=True, null=True) profession = models.CharField(max_length=100, blank=True) bio = models.TextField(blank=True) How do we make all those fields (name, age, profession, bio) required without modifying the database? This is the way I used to do it: # myapp/forms.py from django import forms from .models import MyModel class MyModelForm(forms.ModelForm): name = forms.CharField(max_length=100, required=True) age = forms.IntegerField(required=True) profession = forms.CharField(required=True) bio = forms.TextField(required=True) class Meta: model = MyModel See the problems with this approach? MyModelForm is nearly a copy of MyModel, and was in fact created by copy/pasting model and then modifying it. In software engineering parlance, it violates the principal of Don't Repeat Yourself (DRY) and is fertile ground for introducing bugs. MyModelForm has a bug! Can you spot the bug? The code example below illuminates where I purposefully/gleefully placed an error: class MyModel(models.Model): # … -
Overloading Django Form Fields
One of the patterns we get positive feedback for mentioning in our book is overloading form fields. The problem this pattern handles is the use case of when we have a model with a field(s) that allows for blank values, how do we force users to enter values? For example, assuming the following model: # myapp/models.py from django.db import models class MyModel(models.Model): name = models.CharField(max_length=50, blank=True) age = models.IntegerField(blank=True, null=True) profession = models.CharField(max_length=100, blank=True) bio = models.TextField(blank=True) How do we make all those fields (name, age, profession, bio) required without modifying the database? This is the way I used to do it: # myapp/forms.py from django import forms from .models import MyModel class MyModelForm(forms.ModelForm): name = forms.CharField(max_length=100, required=True) age = forms.IntegerField(required=True) profession = forms.CharField(required=True) bio = forms.TextField(required=True) class Meta: model = MyModel See the problems with this approach? MyModelForm is nearly a copy of MyModel, and was in fact created by copy/pasting model and then modifying it. In software engineering parlance, it violates the principal of Don't Repeat Yourself (DRY) and is fertile ground for introducing bugs. MyModelForm has a bug! Can you spot the bug? The code example below illuminates where I purposefully/gleefully placed an error: class MyModel(models.Model): # … -
In Memory Of Malcolm
In Memory Of Malcolm -
Mails amb Django - II
Enviar un e-mail fent servir plantilles Django Com ja tots sabeu Django té un sistema de plantilles molt eficaç. Normalment les fem servir per mostrar l'html de les nostres aplicacions web, però no estan limitades a això, i com veurem les podem fer servir per generar els nostre correu. La manera de fer-ho és fent servir render_to_string que podem trobar a django.template.loader. Aquesta funció agafa com a paràmetres el nom de la plantilla que volem fer servir i un diccionari amb els paràmetres que farem servir a la plantilla. Agafa un tercer paràmetre, que ha de ser de tipus Context, però que per als nostres objectius no la farem servir gaire. Quan volem enviar un correu ho podem fer dins la vista, però sovint ho farem des de classes d'utilitat, el model o un formulari, on el request no està disponible. Per això hem de tenir em compte que la majoria de vegades no tindrem accés a les variables que normalment estan accessibles a les plantilles mitjançant el context processors. Així doncs que si el correu te links pensau que tot el que siguin referències a arxius i links forçosament necessiten de Sites, MEDIA_URL i STATIC_URL (o fer servir el … -
Django Webmaster Verification
Today I have released version 0.2.1 of django-webmaster-verification. I never took the time to write a post about it, so here you go. The Django application helps to quickly register with various webmaster tools like: Google Webmaster Tools Bing Webmaster Tools Yandex Webmaster Tools Majestic SEO Alexa These tools can help you to monitor your site's performance in search engines which can be quite useful. Django-webmaster-verification is a very simple app that I wrote to avoid repeating setting up the Google tools on each site I manage. It grew a little from there, and today I added support for the Alexa tools. I'm not a big fan of Alexa and I don't think their metrics are very useful. All the people I know who use it are into something like internet marketing, SEO, etc. Nothing against that, but it makes me think that the Alexa data does not represent an average sample of the web population. Anyway, somebody requested it, more power to him! So if you're a Django developer and at least a little interested in SEO give it a try. -
Django Webmaster Verification
Today I have released version 0.2.1 of django-webmaster-verification. I never took the time to write a post about it, so here you go. The Django application helps to quickly register with various webmaster tools like: Google Webmaster Tools Bing Webmaster Tools Yandex Webmaster Tools Majestic SEO Alexa These tools can help you to monitor your site's performance in search engines which can be quite useful. Django-webmaster-verification is a very simple app that I wrote to avoid repeating setting up the Google tools on each site I manage. It grew a little from there, and today I added support for the Alexa tools. I'm not a big fan of Alexa and I don't think their metrics are very useful. All the people I know who use it are into something like internet marketing, SEO, etc. Nothing against that, but it makes me think that the Alexa data does not represent an average sample of the web population. Anyway, somebody requested it, more power to him! So if you're a Django developer and at least a little interested in SEO give it a try. -
Mails amb Django - I
En aquest article, o millor dit, sèrie d'articles, intentaré explicar el millor que pugui la problemàtica que ens trobam en el dia a dia la gent que hem d'enviar correus electrònics des de les nostres aplicacions Django, no tant des del punt de vista de com es fa, sinó del programador que té que desenvolupar d'aplicació. Veurem distints escenaris i com podem tenir una solució que s'adapta a cada un d'ells, de manera que acabem amb un petit receptari, que esper anar ampliant amb l'adjuda de tots. La referència fonamental per Django és la documentació "sending email", miraré de no repetir-la molt, però per completitud convé fer una petita introducció. Configurar el servidor Volem enviar un e-mail ràpid en resposta a un esdeveniment. Per a poder enviar un e-mail des de la nostra aplicació Django prèviament haurem d'haver configurat en nostre servidor SMTP. Això es fa amb les variables del settings EMAIL_HOST, EMAIL_PORT, EMAIL_HOST_USER i EMAIL_HOST_PASSWORD. Ja que hi som convé definir el mail que farem servir en cas que no el posem de manera explícita al DEFAULT_FROM_EMAIL Normalment no hem de definir res si el nostre servidor d'e-mail és el mateix servidor on està l'aplicació i tenim un SMPT … -
Django AJAX Edit Mode
I can't even remember where I saw this, but the suggestion was that viewing and editing data are different operations, and should be different modes. For instance, when viewing some data, you would need to explicitly decide to enter the edit mode. In a web page, this would be by following a link to a page that had a form that allowed for editing. Attempting to submit the form would result in either the same page being displayed, along with any validation errors, or being redirected back to the viewing page. This is the pattern I've been working on implementing with a module for our work system. However, we can reduce the amount of data sent, and the amount of page redraw, by using dynamic element replacement. So, we can have some AJAX that loads in the edit form in-place, and replaces the view form. Saving it then either returns the edit form with validation errors, or the view form again. We can do all of this with one view. Depending upon how it is accessed, it will return either a different template, or render the template differently. ## Solution One: render a different template. {% highlight python %} # … -
My First Kickstarter
In days gone by, getting money from a group of random people over the internet was probably a crime. Now it's the next step in project funding. UPDATE: The kickstarter has gone very, very well. I'll be writing a long post as it draws to a close about the whole experience. I've had the idea of crowdfunding an open source project for a while now, but it wasn't until a few weeks ago that it occurred to me that I could combine my one free day a week (which I used to use for flying lessons) and my pet Django feature into one crowdfundable whole. Thus, today I'm launching the Schema Migrations for Django project on Kickstarter. I've set a goal which would pay for a decent amount of my free days, and I'm hopeful that it will be reached. I'll do a post-mortem blog post on the project and what running a Kickstarter project of this type is like once it's over in two weeks' time - I can say, however, that I've had invaluable feedback from friends and members of the Django community to help me polish the descriptions, tweak the rewards, and generally get it feeling like … -
Configuring No-WWW for IIS on Azure
As part of the rollout of my site redesign, I’ve also switched hosts from WebFaction to Windows Azure. WebFaction was a great value for a shared host, and I’ll probably continue to use it in the future for small Python/Django projects, but I’ve been experimenting with Azure on some other projects and took the opportunity to make the switch. Where’d my .htaccess go? Azure Web Sites use IIS as a web server, not the more common Apache (or Nginx) server widely used across the Unix world. While Azure handles all of the server setup and maintenance for many cases, you’ll still need to get your hands dirty if you need custom handling. One of the big behaviors I needed to maintain in the migration was to continue adherence to the No-WWW philosophy. This means making dancarroll.org the canonical name of my site, with www.dancarroll.org redirecting to the no-www version. I had this set up on the previous iteration of the site using an Apache .htaccess file. It was very easy to find examples of how to do this across the web. RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] RewriteRule ^(.*)$ http://%1/$1 [R=permanent,L]IIS, however, does not use .htaccess files. Instead, … -
Logging in Django
This is a talk I gave at Agiliq on 21-March-2013 as a part of the Hyderabad Python Meetup Group -
Django Meetup – March 21, 2013
Today I had the pleasure of talking about how my team switched from PHP to Python (Django) and the realizations that I had after the process. I learnt a lot about web development in the process and had a great time making the site better for our users. Related posts: Welcome to ProcrastinatingDev DjangoCon 2011 – Real world Django deployment using Chef DjangoCon 2011 – Confessions of Joe Developer -
Serving static files in Django
Serving static files, especially during development, is frequently a pain point. In this post, we will discuss the various settings and directory structure and how they interact with each other. Let's start with development when you have DEBUG = True. We will create a Django project from scratch so that we are fully aware about what file in what directory we are talking about. So, this blog post will be a little longer than it should be. We will try these things with Django 1.4, but these will work on Django 1.3 as well. I have not tested it with Django 1.2, so not sure about 1.2. Setting up the project. If you think you don't need this section, then skip to the next section titled Serving static files. Just make sure to see the directory structure at the end of this section to get an idea of it, so that you will be comfortable in the next section. We will try everything inside a virtual environment. We name our virtual environment as staticvirt. So the command we need is virtualenv staticvirt. ~$ virtualenv staticvirt Next we need to start a Django project inside this virtualenv. Make sure you are … -
Farewell, Malcolm
Following an amazing week at PyCon, I woke up this morning to discover that I'd lost a good friend, and that the Python community has lost one of its most brilliant minds. Details are still unclear, but Malcolm Tredinnick passed away this past weekend, apparently as the result of a seizure. I met Malcolm first online - I was very new to Django, and had just written a blog post about a kludgy method I'd worked out for using a model manager to switch between multiple databases. This was well before multi db became a regular part of the ORM, although at the time it was already a much-requested feature. My method worked, but it was not elegant or pretty, and when I saw Malcolm's name among the comments on my blog post, I was immediately intimidated. But he gave me some tips and taught me a few things through his questions and comments. And when I met him at DjangoCon the following year, he was nothing but kind, encouraging me to continue learning and writing. For a brief time, I lived in Lawrence, Kansas, and I was fortunate enough to get to spend some time with Malcolm whenever he … -
Introduction to Django – presentation
This presentation shows the basics of Django – what is inside the framework and explains the Model-View-Template system. One of the most important parts is a diagram how the request is processed and the response is generated. Shows the project and the application structure and the basic elements – Models, URLs dispatcher, Views and Templates. Introduction to django from Ilian Iliev -
Redesign
This site has been quiet for a long time. My last post was over a year ago in February 2012. That post before that was yet another year prior. With a full-time job and other personal commitments, blog posting and other side projects easily fall off the radar. Take my site’s new design, rolling out today. I initially started working on it in February 2011, going by the file creation timestamps on my machine. I worked on it for a week or so, got some feedback, then dropped it. A year later, I took the big step to actually create a source repository on Bitbucket to make sure the code was backed up somewhere safe (I don’t recall making any other progress at the time). It took me over a year from that point to actually pick up the project and push it through to completion. The design Like the previous design of my site, I have taken a lot of inspiration from people in the Django community. A lot of the design inspiration comes from Steve Losh, who has consistently done an excellent job at clean, readable web design. I’m not sure what I was thinking with the previous … -
Functions in Python Homework
After some delay(please excuse me for it) here are sample solutions of the problems defined in the presentation Functions in Python. Solutions are also available at GitHub. -
#djangosthlm - talking Django hosting
I’m sitting on yet another train from Stockholm back the good old industrial Västerås (or Bästerås as we call it (or Webbsterås;-)), me and my colleague Richard just attended the Django Stockholm meetup, hosted by Dynabyte. Awesome evening with awesome people, moar please=) The first talk of the meetup was Henrik talking AND live coding while using South, really impressive that he almost completely pulled it off! Big kudos to Henrik=) I myself did a small talk about all the different alternatives that exists for hosting a Django site in the year 2013. With a small intro to shared hosting we quickly moved on to DotCloud, Heroku, Gondor etc. We talked a bit about best practices and this best practices bit would maybe fit for a one day hackathon or something. To be able actually nail this. My slides are not much to see since I mainly use them to show of my mad graphical skillz (I mean, WHO doesn’t want a magical pony and rainbows in their presentation). If you want, go ahead and take a look, the interesting part starts at the end, with all the links to better blogposts about hosting than this ;-) Thanks again to … -
Raspberry IO announced at PyCon
PyCon is one of our favorite conferences here at Caktus. We’ve been attending for the past 4 years now and it is amazing to see how much the community has grown. This year is especially special because Jesse Noller and the Python Software Foundation (PSF) came to us to help them build Raspberry IO. The site features work from the Python community and their adventures in using Raspberry Pi with Python. One of our passions at Caktus is collaboration and education. The Raspberry IO application exemplifies just that. Developers share the steps of how they’ve created their projects and interact with other users by providing feedback and answering questions. The site features a Q&A, a wiki and also a community feed aggregator. Users who are extremely active on the site, contributing projects, answering questions will have their projects featured on the homepage. We worked closely with the PSF to also create the logo and branding of the site. Our designer, Julia Elman, drew inspiration from the vintage video game era to create Razzy, the mascot for Raspberry IO. This is Jesse Noller’s last year as the chair of PyCon and we are sad to see him go. This application was his going …