Ponytech

Technology for ponies

Mar 11, 2013

Python integrated SMTP server

When developping web applications one often needs to send mails. It could be for example adress validation, notifications, or whatever. An underrated feature I wanted to share today is the python integrated SMTP server which could be a really good help in testing your application's mail features. Instead of having to deploy an SMTP server or you use your ISP's one, you can just type in your terminal :

python -m smtpd -n -c DebuggingServer localhost:25

This will start a local SMTP server listenning on port 25 (the default). This SMTP server will just print to stdout the mails it receive, along with headers, making your debugging easy.

Please note, that listenning to port 25 requires root privileges (it usually means to prepend sudo to the command). If you don't have such privileges on the machine you are developping you can listen on any other port superior to 1024. You then have to configure your application the use an SMTP non-default port. For example on django you would put in your settings.py :

EMAIL_PORT=2525

Mar 05, 2013

Django 1.5 released

Django 1.5 had finally been released after two release candidates. Let's have a look in details of what it comes with.

It is the first Django version to support Python 3. This feature required a long work and is still considered experimental : do not use it in production. Django 1.6 is planned to be the release ready for Python 3 production. In the meantime, this 1.5 release let you start working on porting your app.

The other big features it adds is a configurable user model to exactly let your application tailor your needs in term of user's specific field or constraints. In previous versions you had to create a sperate table and link it to to the User model through user's profile to add information (facebook id, birthdate, etc) tied to your users. This feature is now deprecated in favor of the configurable user model. Also this new user model lets you specify different constraints. What if you want usernames to be 50 characters long ? This was simply not possible with prior django versions.

If you have models with a large number of fields and your are looking at some optimisations you may be interested by saving a subset of model’s fields. For example:

entry.title = 'New title'
entry.quthor = 'John Doe'

# only update author
entry.save(update_fields='author')

Other noteable additions concerns caching of related model instances, support for streaming responses, a new template tag to ease the use of Javascript in templates.

For an exhaustive list, consult the release notes

← Previous Page 2 of 2