Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Webcast: Creating Enriching Web Applications with Django and Backbone.js
Our technical director, Mark Lavin, will be giving a tutorial on Django and Backbone.js during a free webcast for O’Reilly Media tomorrow, November 6th, 1pm EST. There will be demos and a discussion of common stumbling blocks when building rich client apps. Register today! Here’s a description of his talk: "Django and Backbone are two of the most popular frameworks for web backends and frontends respectively and this webcast will talk about how to use them together effectively. During the session we'll build a simple REST API with Django and connect it to a single page application built with Backbone. This will examine the separation of client and server responsibilities. We'll dive into the differences between client-side and server-side routing and other stumbling blocks that developers encounter when trying to build rich client applications. If you're familiar with Python/Django but unfamiliar with Javascript frameworks, you'll get some useful ideas and examples on how to start integrating the two. If you're a Backbone guru but not comfortable working on the server, you'll learn how the MVC concepts you know from Backbone can translate to building a Django application." Register at O’Reilly Media. -
Webcast: Creating Enriching Web Applications with Django and Backbone.js
Update: The live webcast is now available at O’Reilly Media Our technical director, Mark Lavin, will be giving a tutorial on Django and Backbone.js during a free webcast for O’Reilly Media tomorrow, November 6th, 1pm EST. There will be demos and a discussion of common stumbling blocks when building rich client apps. -
Win Free Copies of “Web Development with Django Cookbook”
Readers would be pleased to know that I have teamed up with Packt Publishing to organize a Giveaway of my book Web Development with Django Cookbook. Three lucky winners stand a chance to win an e-copy of the book. Keep reading to find out how you can be one of the lucky ones. Book OverviewImprove your skills by developing models, forms, views, and templatesCreate a rich user experience using Ajax and other JavaScript techniquesA practical guide to writing and using APIs to import or export data How to Enter?All you need to do is head on over to the book page and look through the product description of the book and drop a line via the comments below this post to let us know what interests you the most about this book. It’s that simple. PrizeWinners will get an e-copy of the Book. DeadlineThe contest will close on the 1st of December, 2014 at 00:00 GMT. Winners will be contacted by email, so be sure to use your real email address when you comment! -
uwsgi and uid
So recently, I moved home for this blog. It used to be on AWS EC2 and is now on Digital Ocean. I wanted to start from scratch so I started on a blank new Ubuntu 14.04 and later rsync'ed over all the data bit by bit (no pun intended). When I moved this site I copied the /etc/uwsgi/apps-enabled/peterbecom.ini file and started it with /etc/init.d/uwsgi start peterbecom. The settings were the same as before: # this is /etc/uwsgi/apps-enabled/peterbecom.ini [uwsgi] virtualenv = /var/lib/django/django-peterbecom/venv pythonpath = /var/lib/django/django-peterbecom user = django master = true processes = 3 env = DJANGO_SETTINGS_MODULE=peterbecom.settings module = django_wsgi2:application But I kept getting this error: Traceback (most recent call last): ... File "/var/lib/django/django-peterbecom/venv/local/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 182, in _cursor self.connection = Database.connect(**conn_params) File "/var/lib/django/django-peterbecom/venv/local/lib/python2.7/site-packages/psycopg2/__init__.py", line 164, in connect conn = _connect(dsn, connection_factory=connection_factory, async=async) psycopg2.OperationalError: FATAL: Peer authentication failed for user "django" What the heck! I thought. I was able to connect perfectly fine with the same config on the old server and here on the new server I was able to do this: django@peterbecom:~/django-peterbecom$ source venv/bin/activate (venv)django@peterbecom:~/django-peterbecom$ ./manage.py shell Python 2.7.6 (default, Mar 22 2014, 22:59:56) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) >>> from … -
uwsgi and uid
So recently, I moved home for this blog. It used to be on AWS EC2 and is now on Digital Ocean. I wanted to start from scratch so I started on a blank new Ubuntu 14.04 and later rsync'ed over all the data bit by bit (no pun intended). When I moved this site I copied the /etc/uwsgi/apps-enabled/peterbecom.ini file and started it with /etc/init.d/uwsgi start peterbecom. The settings were the same as before: # this is /etc/uwsgi/apps-enabled/peterbecom.ini [uwsgi] virtualenv = /var/lib/django/django-peterbecom/venv pythonpath = /var/lib/django/django-peterbecom user = django master = true processes = 3 env = DJANGO_SETTINGS_MODULE=peterbecom.settings module = django_wsgi2:application But I kept getting this error: Traceback (most recent call last): ... File "/var/lib/django/django-peterbecom/venv/local/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 182, in _cursor self.connection = Database.connect(**conn_params) File "/var/lib/django/django-peterbecom/venv/local/lib/python2.7/site-packages/psycopg2/__init__.py", line 164, in connect conn = _connect(dsn, connection_factory=connection_factory, async=async) psycopg2.OperationalError: FATAL: Peer authentication failed for user "django" What the heck! I thought. I was able to connect perfectly fine with the same config on the old server and here on the new server I was able to do this: django@peterbecom:~/django-peterbecom$ source venv/bin/activate (venv)django@peterbecom:~/django-peterbecom$ ./manage.py shell Python 2.7.6 (default, Mar 22 2014, 22:59:56) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) >>> from … -
Django 1.7 et écriture de tests, petites explorations
Je me suis enfin lancé dans l’écriture d’une app django gérant les badges (ou les succès si vous préférez). L’objectif étant de pouvoir réécrire de zéro histoires de rôlistes. L’idée était de tenter de faire une vraie app django, en mode réutilisable, histoire que peut-être des gens puissent trouver intéressant de l’utiliser. Je me suis retrouvé avec deux problèmes concernant mes tests : Souvent on gagne un badge quand on a créé suffisamment de chose (comme des checkin, des billets de blogs ou des contributions diverses). Sauf que je ne voulais pas créer dans mon app des models ne servant à rien, juste pour pouvoir en créer lors de mes tests. Je voulais pouvoir créer des badges se gagnant sur un critère du style ‘être venu un certain nombre de fois sur une URL.’ Donc mettre en place des décorateurs sur des vues. Mais là encore, je ne voulais pas avoir à créer des vues dans mon application rien que pour les tests. Au final, en lisant un peu de doc, j’ai réussi à faire ce que je voulais. Tester un décorateur sans créer des vues inutiles dans son app. Je savais déjà comment forger des requests avec la RequestFactory. … -
Shout-out to eventlog
If you do things with the Django ORM and want an audit trails of all changes you have two options: Insert some cleverness into a pre_save signal that writes down all changes some way. Use eventlog and manually log things in your views. (you have other options too but I'm trying to make a point here) eventlog is almost embarrassingly simple. It's basically just a model with three fields: User An action string A JSON dump field You use it like this: from eventlog.models import log def someview(request): if request.method == 'POST': form = SomeModelForm(request.POST) if form.is_valid(): new_thing = form.save() log(request.user, 'mymodel.create', { 'id': new_thing.id, 'name': new_thing.name, # You can put anything JSON # compatible in here }) return redirect('someotherview') else: form = SomeModelForm() return render(request, 'view.html', {'form': form}) That's all it does. You then have to do something with it. Suppose you have an admin page that only privileged users can see. You can make a simple table/dashboard with these like this: from eventlog.models import Log # Log the model, not log the function def all_events(request): all = Log.objects.all() return render(request, 'all_events.html', {'all': all}) And something like this to to all_events.html: <table> <tr> <th>Who</th><th>When</th><th>What</th><th>Details</th> </tr> {% for event in … -
Shout-out to eventlog
If you do things with the Django ORM and want an audit trails of all changes you have two options: Insert some cleverness into a pre_save signal that writes down all changes some way. Use eventlog and manually log things in your views. (you have other options too but I'm trying to make a point here) eventlog is almost embarrassingly simple. It's basically just a model with three fields: User An action string A JSON dump field You use it like this: from eventlog.models import log def someview(request): if request.method == 'POST': form = SomeModelForm(request.POST) if form.is_valid(): new_thing = form.save() log(request.user, 'mymodel.create', { 'id': new_thing.id, 'name': new_thing.name, # You can put anything JSON # compatible in here }) return redirect('someotherview') else: form = SomeModelForm() return render(request, 'view.html', {'form': form}) That's all it does. You then have to do something with it. Suppose you have an admin page that only privileged users can see. You can make a simple table/dashboard with these like this: from eventlog.models import Log # Log the model, not log the function def all_events(request): all = Log.objects.all() return render(request, 'all_events.html', {'all': all}) And something like this to to all_events.html: <table> <tr> <th>Who</th><th>When</th><th>What</th><th>Details</th> </tr> {% for event in … -
Passing parameters to Django admin action
This post will show how to pass parameters to custom Django admin actions. This post assumes that you have an idea of Django actions. Django provides a default admin action which is 'Delete selected rows'. Changelist page for all the models registered with admin has this action available. This action allows to select multiple rows and delete them in a single POST request. Problem statement We want to allow following Django action from admin. There is a model called Instrument. It has a field price Allow selecting multiple rows for this model and update the value of price for selected rows. Price should not be hardcoded. Admin should be able to enter the price. We should be able to achieve something like: Solution Setup the project first. Setup project Start a Django project inside virtual environment /tmp $ mkvirtualenv custom-actions (custom-actions)/tmp $ django-admin.py startproject actions (custom-actions)/tmp/actions $ python manage.py startapp instruments Writing the model in instruments/models.py class Instrument(models.Model): name = models.CharField(max_length=100) price = models.IntegerField() def __unicode__(self): return self.name Add instruments to INSTALLED_APPS Run syncdb (custom-actions)/tmp/actions $ python manage.py syncdb Register this model with admin in instruments/admin.py from django.contrib import admin from .models import Instrument admin.site.register(Instrument) You should be able to … -
Travis and coveralls for private repo
Before we begin, i recommend you to read this first Continous integration with travis and coveralls.io for Django apps. Here is how .travis.yml example file looks like: language: python python: - 2.7 install: - pip install -r requirements.txt - pip install coveralls script: coverage run manage.py test after_success: coveralls Setting up coveralls for private repositories requires you to add just one more file .coveralls.yml. 1) Create a .coveralls.yml and make sure it resides in your project's root directory. 2) Add the following to this file: service_name: travis-pro repo_token: **** service_name is to specify where Coveralls should look to find additional information about your builds. You can get the repo_token from your repository's page on Coveralls, if you have the admin privileges. This is to tell which project on Coveralls your project maps to. Make sure your repo_token remains secret and do not add this to your public repository. 3) Add the file, commit it and make a git push. 4) If everything is OK you should see some thing like the below in your travis build: Submitting coverage to coveralls.io... Coverage submitted! Job #22.1 https://coveralls.io/jobs/54864565 Thats it now get a coverage badge from coveralls and add this badge in your … -
Ubuntu PPA madness
I'm going flipping insane. In ye olde days, when I was programming with the python CMS Plone, my dependencies were limited to python and PIL. Perhaps lxml. LXML was a pain to install sometimes, but there were ways around it. Working on OSX was no problem. Server setup? Ubuntu. The only thing you really had to watch in those days was your python version. Does this old site still depends on python 2.4 or is it fine to use 2.6? Plone had its own Zope database, so you didn't even need database bindings. Now I'm working on Django sites. No problem with Django, btw! But... the sites we build with it are pretty elaborate geographical websites with lots of dependencies. Mapnik, matplotlib, numpy, scipy, gdal, spatialite, postgis. And that's not the full list. So developing on OSX is no fun anymore, using a virtual machine (virtualbox or vmware) is a necessity. So: Ubuntu. But... ubuntu 12.04, which we still use on most of the servers, has too-old versions of several of those packages. We need a newer gdal, for instance. And a newer spatialite. The common solution is to use a PPA for that, like ubuntugis-stable. Now for some random … -
Using Arrow for Better Datetime
Learn how to be better at dealing with dates and times in python in a few short minutes. Working with dates and times in python is a lot easier than other languages, but can be convoluted and confusing. Arrow provides a convenient api for working with and manipulating dates and times. See what it takes to get started.Watch Now... -
Contributing Back to the Community - Django Cookbook
In the early beginning of year 2014, the IT book publishing company "Packt Publishing" contacted me with an interesting offer: to share my Django experience in a form of a book. I thought it might be a good challenge for me and also value for the Django community, as I had been working with Django for 7 years or so, and during that time there was quite a lot of knowledge gathered and used practically. So for the next 9 months on late evenings and weekends I was adapting some of the most useful code snippets and describing them in the book. The great staff from the Packt Publishing helped me to structure the content, make everything clear and understandable, and get the grammar correct. Finally, the book was released and it's called "Web Development with Django Cookbook". This book is written for intermediate or advanced Django web developers. When writing the book, my own purpose was not to fully cover every possible web development task, but rather to have enough useful bits of knowledge for those who seek information about web development with Django. The book was written in the format of recipes. There are over 70 recipes giving … -
Useful Shell Aliases For Python (and Django) Developers!
We use almost all same commands everyday. There are a handful of aliases for git & docker written by a few. But it seems no one has mentioned any aliases for python. I just made a handful of aliases so that I can type little bit less in terminal. Here are a few of them.alias py='python'alias ipy='ipython'alias py3='python3'alias ipy3='ipython3'alias wo='workon'alias pf='pip freeze | sort'alias pi='pip install'alias pun='pip uninstall'alias dj="python manage.py"alias drs="python manage.py runserver"alias dsh="python manage.py shell"alias dsm="python manage.py schemamigration"alias dmm="python manage.py makemigration"alias dm="python manage.py migrate"alias ddd="python manage.py dumpdata"alias dld="python manage.py loaddata"alias dt="python manage.py test"# Show all alias related pythonpya() { alias | grep 'python\|workon\|pip' | \ sed "s/^\([^=]*\)=\(.*\)/\1 => \2/"| sed "s/['|\']//g";}These are a few repeatedly used commands. It takes time even to get used to aliases. So I added pya function at the end. In case if you don't remember aliases or if you want to checkout what aliases related to python are present in your dot file, you can use it.Just add the above aliases to your .bashrc or .zshrc or whatever shell you are using and source it. That's it. Hpy alsng! -
Ultimate Front End Development Setup
Ultimate Front End Development Setup -
5 million votes and counting at Rockhall.com
5 million votes and counting at Rockhall.com -
django-html-validator
A couple of weeks ago we had accidentally broken our production server (for a particular report) because of broken HTML. It was an unclosed tag which rendered everything after that tag to just plain white. Our comprehensive test suite failed to notice it because it didn't look at details like that. And when it was tested manually we simply missed the conditional situation when it was caused. Neither good excuses. So it got me thinking how can we incorporate HTML (html5 in particular) validation into our test suite. So I wrote a little gist and used it a bit on a couple of projects and was quite pleased with the results. But I thought this might be something worthwhile to keep around for future projects or for other people who can't just copy-n-paste a gist. With that in mind I put together a little package with a README and a setup.py and now you can use it too. There are however some caveats. Especially if you intend to run it as part of your test suite. Caveat number 1 You can't flood htmlvalidator.nu. Well, you can I guess. It would be really evil of you and kittens will die. If … -
django-html-validator
A couple of weeks ago we had accidentally broken our production server (for a particular report) because of broken HTML. It was an unclosed tag which rendered everything after that tag to just plain white. Our comprehensive test suite failed to notice it because it didn't look at details like that. And when it was tested manually we simply missed the conditional situation when it was caused. Neither good excuses. So it got me thinking how can we incorporate HTML (html5 in particular) validation into our test suite. So I wrote a little gist and used it a bit on a couple of projects and was quite pleased with the results. But I thought this might be something worthwhile to keep around for future projects or for other people who can't just copy-n-paste a gist. With that in mind I put together a little package with a README and a setup.py and now you can use it too. There are however some caveats. Especially if you intend to run it as part of your test suite. Caveat number 1 You can't flood htmlvalidator.nu. Well, you can I guess. It would be really evil of you and kittens will die. If … -
Call for contributors – Stream-Framework 1.1
Reblog, from: Call for contributors – Stream-Framework 1.1 Share and Enjoy: -
Call for contributors - Stream-Framework 1.1
Today we’ve released Stream Framework 1.1. Development has been a bit slow pending the rename from Feedly to Stream-Framework. Fortunately the community is growing faster than ever. Many users of GetStream.io are looking at Stream Framework and vice versa. We would like to take this moment to encourage contributions. We’re actively accepting pull requests and appreciate all the help. Especially the python 3 support on the roadmap is something which you can easily get started with. So if you’ve been searching for a project to contribute to, now is a good time :) Roadmap Python 3 support (pending CQLEngine) Documentation improvements (see issues) Database backend to facilitate small projects Relevancy based feeds (far future) API similar to getstream.io to allow other languages to Stream Framework (far future) Let us know which features you guys are looking forward to! What’s new Since the last blogpost we’ve made the following changes: Ability to customize the Activity object used in feeds and aggregated activity used in aggregated feeds. Hooks to collect metrics Updated CQLengine and Python-Driver Ability to filter Redis & Cassandra feeds using the .filter syntax() Ability to order Redis using the .order syntax (Thanks Anislav) Redis improvements to counts (Again, many … -
We’re a Gold Sponsor of Multiple Template Engines for Django
One of the most common components in Django that is replaced by alternatives is templates. The reason is either or both performance and design related. While there are numerous template bridge libraries to support the use of Jinja2, Mako, and other template languages in Django, there is not a standard API. This is unfortunate, because one of the virtues of using Django is that we can share our efforts across third-party libraries. Fortunately, Django core developer, Aymeric Augustin has started a crowdfunding campaign to create first-class support for third-party template engines in Django. We’re excited! Two Scoops Press is proud to be a gold sponsor for Django core developer Aymeric Augustin’s Multiple Template Engines for Django campaign on Indiegogo. This is the last day of the campaign, so now’s your chance to show support as well. -
We’re a Gold Sponsor of Multiple Template Engines for Django
One of the most common components in Django that is replaced by alternatives is templates. The reason is either or both performance and design related. While there are numerous template bridge libraries to support the use of Jinja2, Mako, and other template languages in Django, there is not a standard API. This is unfortunate, because one of the virtues of using Django is that we can share our efforts across third-party libraries. Fortunately, Django core developer, Aymeric Augustin has started a crowdfunding campaign to create first-class support for third-party template engines in Django. We’re excited! Two Scoops Press is proud to be a gold sponsor for Django core developer Aymeric Augustin’s Multiple Template Engines for Django campaign on Indiegogo. This is the last day of the campaign, so now’s your chance to show support as well. -
We’re a Gold Sponsor of Multiple Template Engines for Django
One of the most common components in Django that is replaced by alternatives is templates. The reason is either or both performance and design related. While there are numerous template bridge libraries to support the use of Jinja2, Mako, and other template languages in Django, there is not a standard API. This is unfortunate, because one of the virtues of using Django is that we can share our efforts across third-party libraries. Fortunately, Django core developer, Aymeric Augustin has started a crowdfunding campaign to create first-class support for third-party template engines in Django. We’re excited! Two Scoops Press is proud to be a gold sponsor for Django core developer Aymeric Augustin’s Multiple Template Engines for Django campaign on Indiegogo. This is the last day of the campaign, so now’s your chance to show support as well. -
Introducing stream-django, our first framework integration
We are proud to announce the first release of Stream-Django, a python package to add activity feeds to Django applications. This package comes with built-in integration for Django models, out-of-the-box feed management and some template helpers to presenting feeds to your users. The package is available on Github, you can find a detailed explanation here. We also updated our example application to use stream-django. Tommaso -
Django runserver_plus with SSL and Firefox 33
So with version 33, Firefox did something rather annoying, they now use a more restrictive library that rejects connections to servers running older versions of SSL. On the one hand, this is pretty awesome because at some point we all need to grow up and start using modern encryption, but on the other, it can make development really difficult when all you really need a an SSL setup -- any SSL setup to make your local development environment Just Work. We've been using django-extenstion's runserver_plus feature, which is awesome because it includes a browser-based debugger and other really cool stuff, but also importantly, it supports the ability for you to run the Django runserver in SSL mode. This means that you can do stuff like: ./manage.py runserver_plus --cert=/tmp/temporary.cert And that's enough for you to be able to access your site over SSL: https://localhost:8000/ However, now that Firefox has thrown this monkeywrench into things, we spent far too much time today trying to figure out what was wrong and how to fix it, so I'm posting the answer here: Basically, you just need a better cert than the one django-extensions creates for you automatically. So, instead of just running --cert=/path/to/file and …