Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
One to Many
As of yesterday, I completed and merged the first of the three upcoming Evennia features I mentioned in my Churning Behind the Scenes blog post: the "Multiple Characters per Player" feature.Evennia makes a strict division between Player (this is an object storing login-info and represents the person connecting to the game) and their Character (their representation in-game; Characters are just Objects with some nice defaults). When you log into the game with a client, a Session tracks that particular connection.Previously the Player class would normally only handle one Session at a time. This made for an easy implementation and this behavior is quite familiar to users of many other mud code bases. There was an option to allow more than one Session, but each were then treated equally: all Sessions would see the same returns and the same in-game entities were controlled by all (and giving the quit command from one would kick all out).What changed now is that the Player class will manage each Session separately, without interfering with other Sessions connected to the same Player. Each Session can be connected, through the Player, to an individual Character. So multiple Characters could in principle be controlled simultaneously by the … -
Enabling CORS in Angular JS
I was recently experimenting with building an API with django-tastypie and make it accessible via CORS, so it can be used from a different host from an AngularJS app. For the Django part it was relatively straightforward. I could have either written my own Middleware, dealing with incoming CORS requests, but decided to use django-cors-headers in the end. Following the instructions in the github repo and adding my host where AngularJS is hosted to the CORS_ORIGIN_WHITELIST setting did enable the Django server to handle CORS. With AngularJS it was a little more tricky, mainly because information is spread all over the web. Beside the fact that I was trying to implement a service using ngResource to communicate with the API, the following did enable AngularJS to send its requests with the appropriate CORS headers globally for the whole app: var myApp = angular.module('myApp', [ 'myAppApiService']); myApp.config(['$httpProvider', function($httpProvider) { $httpProvider.defaults.useXDomain = true; delete $httpProvider.defaults.headers.common['X-Requested-With']; } ]); _ Just setting useXDomain to true is not enough. AJAX request are also send with the X-Requested-With header, which indicate them as being AJAX. Removing the header is necessary, so the server is not rejecting the incoming request. -
Django Facebook – 1.5 and custom user model support
Django Facebook now officially supports Django 1.5 and custom user models! Go try it out and upgrade to pip version 5.1.1. It’s backwards compatible and you can choose if you want to keep on using profiles, or migrate to the new custom user model. Installation instructions can be found on github. Contributing Thanks for all the contributions! My startup (Fashiolista) depends on a reliable Facebook integration and maintaining it would not be possible without all the pull requests from the community. Contributions are strongly appreciated. Seriously, give Github a try, fork and get started :) About Django Facebook Django Facebook enables your users to easily register using the Facebook API. It converts the Facebook user data and creates regular User and Profile objects. This makes it easy to integrate with your existing Django application. I’ve built it for my startup Fashiolista.com and it’s currently used in production with thousands of signups per day. For a demo of the signup flow have a look at Fashiolista’s landing page (fashiolista.com) After registration Django Facebook gives you access to user’s graph. Allowing for applications such as: Open graph/ Timeline functionality Seamless personalization Inviting friends Finding friends Posting to a users profile Django Facebook … -
The Easy Form Views Pattern Controversy
This isn't a controversy 'per se', except perhaps in the feverish depths of my brain. In the summer of 2010 Frank Wiles of Revsys exposed me to what I later called the "Easy Form Views" pattern when creating Django form function views. I used this technique in a variety of places, including Django Packages and the documentation for django-uni-form (which is rebooted as django-crispy-forms). At DjangoCon 2011 Miguel Araujo and I opened our Advanced Django Forms Usage talk at DjangoCon 2011 with this technique. It’s a pattern that reduces the complexity of using forms in Django function-based views by flattening the form handling code. How the Easy Form Views pattern works Normally, function-based views in Django that handle form processing look something like this: def my_view(request, template_name="my_app/my_form.html"): if request.method == 'POST': form = MyForm(request.POST) if form.is_valid(): do_x() # custom logic here return redirect('home') else: form = MyForm() return render(request, template_name, {'form': form}) In contrast, the Easy Form Views pattern works like this: def my_view(request, template_name="my_app/my_form.html"): form = MyForm(request.POST or None) if form.is_valid(): do_x() # custom logic here return redirect('home') return render(request, template_name, {'form': form}) The way this works is that the django.http.HttpRequest object has a POST attribute that defaults to … -
The Easy Form Views Pattern Controversy
In the summer of 2010 Frank Wiles of Revsys exposed me to what I later called the "Easy Form Views" pattern when creating Django form function views. I used this technique in a variety of places, including Django Packages and the documentation for django-uni-form (which is rebooted as django-crispy-forms). At DjangoCon 2011 Miguel Araujo and I opened our Advanced Django Forms Usage talk at DjangoCon 2011 with this technique. It’s a pattern that reduces the complexity of using forms in Django function-based views by flattening the form handling code. How the Easy Form Views pattern works Normally, function-based views in Django that handle form processing look something like this: def my_view(request, template_name="my_app/my_form.html"): if request.method == 'POST': form = MyForm(request.POST) if form.is_valid(): do_x() # custom logic here return redirect('home') else: form = MyForm() return render(request, template_name, {'form': form}) In contrast, the Easy Form Views pattern works like this: def my_view(request, template_name="my_app/my_form.html"): form = MyForm(request.POST or None) if form.is_valid(): do_x() # custom logic here return redirect('home') return render(request, template_name, {'form': form}) The way this works is that the django.http.HttpRequest object has a POST attribute that defaults to an empty dictionary-like object, even if the request’s method is equal to "GET". Since we … -
Stonewall Jackson and documentation
Today it is 150 years ago that Stonewall Jackson died. Not everyone will recognize the name: it is a general from the American civil war. And a good one at that! Bear with me, I'll have a programming-related comment to make on documentation :-) If you know a bit about the second world war, you might have heard about the German general Erwin Rommel. Jackson's fame was a bit like that. If you had to fight Jackson or Rommel, it didn't really matter that you had more men and equipment: he'd beat the crap out of you anyway. Once at a time Jackson's 15000 men ran circles around 60000 opponents and repeatedly beat them. That's 1:4. And they won. Both Jackson and Rommel seemed to have a Fingerspitzengefühl. They'd known instinctively when to do or not do something. When to lay in wait and when to strike out despite the odds. Both also seemed to be one-of-a-kind. I mean it in the sense that they could not teach others to do the same. It was all in their own head. It was all dependent upon them. And at least Jackson didn't tell anything to his subordinates; he was secretive. When … -
Starting Off
Welcome to the first of my Django Diaries, where I'll be detailing the progress I'm making on my Schema Alteration project. After a very successful Kickstarter, I had the unfortunate situation of a couple of successive trips abroad, and so initial work has been a bit more delayed than I would have liked. However, thanks to securing more time to work on the project every week, progress should be faster than planned from now on. The plan is that these diaries will contain a rough summary of the work I've been doing; they're here both to help engage you (the slightly-too-interested public) in the work I'm doing, as well as providing some transparency of the work I'm doing. If you want to hear more about a certain issue, feel free to get in touch with me - see the About page for my contact details. I'd love to explain as much as I can to those who are interested! Laying the Groundwork The first task I faced was to go back to my original Django branch and get it up-to-date with the changes in trunk. The only change that affected the schema work was Aymeric Augustin's transaction changes - he's … -
Making Django play nicely with AngularJS
Introduction During the development of a new feature to allow users to "pin" content to read at a later date, we came up against the age-old problem in our application - how to write javascript without a whole heap of boilerplate. We've tried various approaches in the past, e.g. using Handlebars to template data received from the server, and wrapping up some repeated operations in some hand-rolled "libraries". We'd chosen not to use a javascript framework previously since jQuery is a pretty powerful tool which could be used to meet most of our needs since our application consists of many pages which require a small degree of progressive enhancement and not a full-blown client-side application. This pinning challenge was a bit different from problems we'd come across before since there would be a pins widget on almost every page in the site and any page that contained our editorial or user-contributed content would be eligible for a pinning control, so we decided that it was the right time to choose a framework, even if it were one with a fairly minimal feature-set for wrapping some low-level operations. Why AngularJS? We identified several things which cause us irritation and slow us … -
Making Django 1.5 compatible with django-bcrypt
Last night I took the opportunity to upgrade all of getsentry.com to Django 1.5. While most things were fairly trivial to sort out, we hit one less obvious (and pretty critical) bug during the migration surrounding django-bcrypt. This bug would only present itself if you’ve transitioned from … -
Making Django 1.5 compatible with django-bcrypt
Last night I took the opportunity to upgrade all of getsentry.com to Django 1.5. While most things were fairly trivial to sort out, we hit one less obvious (and pretty critical) bug during the migration surrounding django-bcrypt. This bug would only present itself if you've transitioned from old... -
Upgrades: Django Old to Django New
Upgrades: Making the Jump from Django Old to Django New Sometimes we are faced with the challenge of upgrading old Django-based projects. The task can be daunting, as a lot has happened in Django within the last few years. Since Django 1.1.1, Django has been through 15 micro ... -
Making Django 1.5 compatible with django-bcrypt
Last night I took the opportunity to upgrade all of getsentry.com to Django 1.5. While most things were fairly trivial to sort out, we hit one less obvious (and pretty critical) bug during the migration surrounding django-bcrypt. This bug would only present itself if you've transitioned from old... -
Einladung zur Django-UserGroup Hamburg am 08. Mai
Das nächste Treffen der Django-UserGroup Hamburg findet am Mittwoch, den 08.05.2013 um 19:30 statt. Dieses Mal treffen wir uns wieder in den Räumen der intosite GmbH im Poßmoorweg 1 (3.OG) in 22301 Hamburg. Die Organisation der Django-UserGroup Hamburg findet ab jetzt über Meetup statt. Um automatisch über zukünftige Treffen informiert zu werden, werdet bitte Mitglied in unserer Meetup-Gruppe: http://www.meetup.com/django-hh Da wir in den Räumlichkeiten einen Beamer zur Verfügung haben hat jeder Teilnehmer die Möglichkeit einen kurzen Vortrag (Format: Lightning Talks oder etwas länger) zu halten. Konkrete Vorträge ergeben sich erfahrungsgemäß vor Ort. Eingeladen ist wie immer jeder der Interesse hat sich mit anderen Djangonauten auszutauschen. Eine Anmeldung ist nicht erforderlich, hilft aber bei der Planung. Weitere Informationen über die UserGroup gibt auf unserer Webseite www.dughh.de. -
New Committers for Tastypie & Haystack
New Committers for Tastypie & Haystack -
Tools we used to write Two Scoops of Django
Because of the ubiquitousness of reStructuredText in the lives of Python developers and the advocacy of it, it's not uncommon for people to assume we used it to write our book. However, that's not really the case. The short Answer is we used: reStructuredText (RST) Google Documents Apple Pages LaTeX The long answer is the rest of this posting. Since writing the book was broken up into three major stages 'alpha', 'beta', and 'final', so have I broken up blog article. Alpha Days Some of the original alpha material was written in rough draft form as RST since it was what we were used to using. Unfortunately, the PDF generation wasn't to our liking, so we immediately began looking at other options. Since she enjoyed using it at MIT and because it gave us greater individual control, Audrey wanted to switch to LaTeX. I was worried about the challenges of learning LaTeX, so we compromised and moved to Google Documents. For the most part, Google Documents was great in the early stages. The real-time collaborative nature was handy, but the gem was the comment system. It gave us the ability to have line-by-line written dialogues with our technical reviewers. However, … -
Tools we used to write Two Scoops of Django
Because of the ubiquitousness of reStructuredText in the lives of Python developers and the advocacy of it, it's not uncommon for people to assume we used it to write our book. However, that's not really the case. The short answer is we used: reStructuredText (RST) Google Documents Apple Pages LaTeX The long answer is the rest of this posting. Since writing the book was broken up into three major stages 'alpha', 'beta', and 'final', so have I broken up blog article. Alpha Days Some of the original alpha material was written in rough draft form as RST since it was what we were used to using. Unfortunately, the PDF generation wasn't to our liking, so we immediately began looking at other options. Since she enjoyed using it at MIT and because it gave us greater individual control, Audrey wanted to switch to LaTeX. I was worried about the challenges of learning LaTeX, so we compromised and moved to Google Documents. For the most part, Google Documents was great in the early stages. The real-time collaborative nature was handy, but the gem was the comment system. It gave us the ability to have line-by-line written dialogues with our technical reviewers. However, … -
Box Office Champs Launches
A fantasy movie game built using Django. This is a very easy game where you pick the 15 movies you think will be the highest grossing movies of the season. You can create a group and compete with your friends. You should give the site a try today. Iron Man 3 opens tomorrow and you definitely want to have that movie on your roster. Unlike fantasy sports, you can play this game 4 times a year. The summer season starts tomorrow. Kudos to Rudy Menendez who did principal development and game design and Noah Wenz for design and HTML. The site was with spare time over the last few months. Put together, development time was about 2-3 weeks. If you need a fantasy site done, contact Ed or Rudy Menendez and we can help you out. -
PiCloud: near-free Heroku background worker for Django in 3 steps
Do you know PiCloud offers free 20 hours/mo of background processing of jobs, billed for msec of CPU running? Combo this with Heroku PaaS hosting solution allowed us at KomboBreaker to deploy background-heavy products for little money (and no worker dyno). Although using PiCloud with Heroku and Django is not “that trivial”. Follow this 3 steps and offload you Heroku jobs to PiCloud for your start-up: 1) Add ‘cloud' to your ‘requirements.txt’ file Adding a line with the text ‘cloud' it to the bottom of your requirements.txt file … Continue reading → -
A quick review of Django 1.5 Application Development Starter ebook
Django 1.5 Application Development Starter is an ebook published by Packt Publishing and sold for less than 7 EUR at the time of writing this review. Few weeks ago the publisher contacted me if I could review their new Django ebook. It took me some time but I managed to go through it and get the big picture of this book. The "Django 1.5 Application Development Starter" consist of 63 pages describing Django 1.5 (based on RC 1 and Python 2) framework - how to get started by developing a typical application using models, forms, templates or admin panel and other framework features. The ebook is divided into few big chapters. At start we get to know Django - what it is and why it's s cool. Next the installation process, third project creation quickstart. After that we get a bigger chapter describing framework components - settings, models, url patterns, templates, forms and admin panel. It's not a technical description. All is don on an example application (questions and answers) that is being developed page by page using mentioned framework components. By the end we get some information about deployment - basic server configuration including Nginx. The book ends with … -
Django Facebook hotfix, update to 5.0.13
Last night Facebook changed the format they use for codes. (codes are an intermediate step in the process of requesting access tokens.) This change broke the caching for the convert code step for Django Facebook, breaking login, connect and registration functionality. Fortunately this was quickly reported by developers in a country where there was no Queensday yesterday. I encourage everybody to update to 5.0.13 to make sure your Facebook integration keeps on working. Share and Enjoy: -
AngularJS to PyGame: Caktus’ 2nd ShipIt Day
We had our 2nd ShipIt Day at Caktus last week. ShipIt (coined by Atlassian), in case you don’t know, is an exercise that allows your team to work on alternative projects in a 24-hour hackathon. We brainstorm ideas related to Caktus, break into small groups and try to build a project by the end of the day on Friday. It’s a lot of fun and provides an opportunity to work on internal tools, try something new and collaborate together. We had a lot of great projects this time around. From diving into AngularJS to building a PyGame for learning how to program. I’ve written up a short summary here to show everyone what we worked on. You can view a whole Flickr gallery of our ShipIt day here. Learn a New Framework We build most projects in Django at Caktus, but it’s fun to learn about alternatives. Dan, Karen and Mark teamed up to explore alternative languages and frameworks. The idea was to build a HTTP service in the framework of your choice that would return whether or not a word was spelled correctly. A simple Python-based test suite was used to test spell checking a few words. In the end, 5 languages/frameworks were tested: Lua, … -
Common testing scenarios for Django app.
People are often confused regarding what tests to write. Let's look into some scenarios for which tests can be written. Setting up the project We start a Django project inside a virtual environment. In this post we would be using django 1.4. (dj)~/play/dj$ django-admin.py startproject testcases Let's start an app named blog. (dj)~/play/dj/testcases$ python manage.py startapp blog We will have the following model in blog/models.py: class BlogEntry(models.Model): title = models.CharField(max_length=100) text = models.TextField() is_published = models.BooleanField(default=True) user = models.ForeignKey(User) We will do test driven development which requires: Thinking about our assumption. Writing the test to satisfy that assumption. Run the test and it will fail since we won't have view written till this point. Adding the view. Run the test and fixing the view or anything else till our test passes. If I could not explain the project structure properly, you can find the complete project here. First test We want a page which shows all blog entries at url /blog/entries/. We need following line in urls i.e testcases/urls.py url(r'^blog/', include('blog.urls')), blog/urls.py url(r'^entries/$', 'blog.views.entries', name='entries'), Let's add a test which satisfies our assumption. Every app we create gets a tests.py where we can put our tests. You can remove the … -
Python Interview Question and Answers
For the last few weeks I have been interviewing several people for Python/Django developers so I thought that it might be helpful to show the questions I am asking together with the answers. The reason is … OK, let me tell you a story first. I remember when one of my university professors introduced to us his professor – the one who thought him. It was a really short visit but I still remember one if the things he said. “Ignorance is not bad, the bad thing is when you do no want to learn.” So back to the reason – if you have at least taken care to prepare for the interview, look for a standard questions and their answers and learn them this is a good start. Answering these question may not get you the job you are applying for but learning them will give you some valuable knowledge about Python. This post will include the questions that are Python specific and I’ll post the Django question separately. How are arguments passed – by reference of by value? The short answer is by value. The longer one starts with the fact that this terminology is probably not the … -
Structuring flask apps, a how-to for those coming from Django
The other day a friend of mine was trying out flask-peewee and he had some questions about the best way to structure his app to avoid triggering circular imports. For someone new to flask, this can be a bit of a puzzler, especially if you're coming from django which automatically imports your modules. In this post I'll walk through how I like to structure my flask apps to avoid circular imports. In my examples I'll be showing how to use "flask-peewee", but the same technique should be applicable for other flask plugins. I'll walk through the modules I commonly use in my apps, then show how to tie them all together and provide a single entrypoint into your app. Project layout I use a structure that may look familiar to users of the django framework: admin.py - Where you register models with the site admin interface api.py - Where you register models to be exposed via a REST-ful API app.py - Your "Flask" application, configuration, and database. auth.py - The authentication system used to protect access to the admin. main.py - this is the secret sauce models.py - Database models for use with your ORM, business logic, etc. views.py - … -
Structuring flask apps, a how-to for those coming from Django
The other day a friend of mine was trying out flask-peewee and he had some questions about the best way to structure his app to avoid triggering circular imports. For someone new to flask, this can be a bit of a puzzler, especially if you're coming from django which automatically imports your modules. In this post I'll walk through how I like to structure my flask apps to avoid circular imports. In my examples I'll be showing how to use "flask-peewee", but the same technique should be applicable for other flask plugins. I'll walk through the modules I commonly use in my apps, then show how to tie them all together and provide a single entrypoint into your app. Project layout I use a structure that may look familiar to users of the django framework: admin.py - Where you register models with the site admin interface api.py - Where you register models to be exposed via a REST-ful API app.py - Your "Flask" application, configuration, and database. auth.py - The authentication system used to protect access to the admin. main.py - this is the secret sauce models.py - Database models for use with your ORM, business logic, etc. views.py - …