Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Using Appengine with Django, why it is pretty much unusable
We are hard at work building 42topics.com, and are looking at the best places to deploy this. So when I heard about Appengine, with out of box Django support(gasp!) I was delighted. After using it for a day, and posting a tutorial, I am so disappointed. Peeves in no particular order. Appengine is a very constrained environment, so out goes any chance to run background jobs. The ORM-API is very similar to Django, but yet the Django API is much better. modelobj.filter('attr =', value1).filter('attr2 =', value2) or modelobj.filter(attr = value1, attr2 = value2). Putting entity level operations on modelobj.manager is much cleaner that making them classmethods, as argued here. Very half baked documentation. Releasing without sufficient testing on windows. If you follow the Getting started guide, and are on windows, I hope you like debugging regexes NO JOINS? Ok so I can use obj.master to simlute this. Umm can I get GROUP BY? What about UNION? Admittedly Bigtable is not relational, but are you telling me Google built all their search without a way to simulate GROUP BY. PDB does not work on dev server. With Django's dev server, I put breakpoints with PDB all the time, and it works … -
Two Django+Appengine Tutorials
I have posted two Tutorials for Using Django with Appengine. For people who do not know Django For people who already know Django see what we build in this tutorial And here a few good links about the topic. James Bennet tells exactly why Appengine and Django are not so good together. Ian Bicking has an interesting take on how Appengine can change the economics of Python hosting. The guys at Joyent reading my mind on why I or you can not deploy any production site on Appengine. (Hint. you mean I can never move away, without writing half my code?) -
New tutorial - Building a search engine with Appengine and Yahoo
I wrote a new tutorial on building a search engine using Appengine, and Yahoo Search API here. This uses pure Appengine API, and not Django, and is a tutorial on how to use Appengine without Django. -
Five Things I Hate About Django.
The five things I hate about * meme seems have died down, and memes, should not be allowed to die. Of course I love Django, and have bet very heavily on it. But we do not know a topic, until we know it warts, so here you go. The listing is in no particular order, so sorry no numbering. Ajax with Django is hard: Most of the Django Community has decided that bundling Javascript helpers with a python framework is bad idea. Though I can understand the reasoning, (argued here and rebuttal), that Javascript is so basic that you can not be expected to not know it, I can not agree with it. SQL is as basic as Javascript, and yet we have ORM for abstracting away the common and the tedious. Of Course, with simplejson, and a good Javascript library, you can build Ajax apps fast and with only a minimal amout of fuss. And yet switching between Python and Javascript, twice every hour is a huge time drain. Eg. I put commas after the last element in Python arrays, with JS this would work in FF, but fail with weird errors in IE. Lack of identity map: If … -
An interview with Malcolm Tredinnick - Django core contributor
Malcolm Tredinnick is a core contributor to Django, and was the driving force behind the Queryset-refactor branch of Django, which adds important capabilities such as model inheritance. He has a long association with OSS, and contributed significantly to GNOME and Django. He graciously agreed to be interviewed at 42topics blog. Malcolm's blog, Defying Classification, can be read here. Shabda: Would you tell a few things about yourself, how did you get involved with OSS and Gnome, and with Django? Malcolm: Here are some recollections I've written about: 1 and 2 Short version; started using Linux in university as a poor undergrad; kept using it since then (started back in 1993). Started using GNOME in 1999 (after trying a very early version of Qt and what became KDE), started contributing to GNOME about 12 months later (mid-2000). Started using Django in October 2005, I guess (a few months after it was open sourced) and haven't stopped. Started contributing patches more or less immediately and was given commit privileges about March of 2006, from memory. Shabda: So what is one thing in Django which you absolutely love, and one thing which you think Django should have done differently? Malcolm: I guess Django's … -
Interview with James Bennett - Django release manager
James Bennett is the release manager of Django, and a long time contributor. He works on Ellington, a CMS designed for news organizations. His book, Practical Django Projects, is being published by Apress, and is scheduled to hit bookshelves in June 2008. He graciously agreed to be interviewed at the 42topics.com blog. His blog, The B-List, can be found here. Shabda: Would you tell something about yourself, how did you get started with Django, and what other OSS projects are you involved with? James: I got into Django fairly soon after the initial public release; I'd been doing PHP and Perl work (mostly Textpattern on the PHP side, Scoop on the Perl side), and I was working on teaching myself Ruby and Rails because it looked interesting. But I'd always liked Python; it was just that there weren't a whole lot of good options for Python web development at that point. You could do Zope, or you could do Twisted, but they both had pretty steep learning curves when compared to the type of work I was doing, so it just wasn't worth it. Django changed that; I think I did the tutorial the day it was released, and I … -
An interview with Russell Keith-Magee - Django core contributor
Russell Keith-Magee is a longtime core contributor to Django. He has worked extensively with the Django testing and serialization components. He is currently working on django-evolution, the ability to do schema evolution from Django, an often requested feature, and is mentoring a GSOC proposal to add aggregate queries support to Django ORM. He is currently a Senior R&D Software Engineer at plugger.com.au. He graciously agreed to an email interview with the 42topics blog. Shabda: Would you tell a little about yourself? How did you get started with Django? What areas of Django have you contributed to? Russell: I'm a thirty-one year old, father of one, living in the most isolated capital city in the world - Perth, Western Australia. Strangely, for all my involvement in Django, my background has almost nothing to do with the web. I studied Physics as an undergraduate, and studied neural networks for my PhD. My first job was with a startup in the defence industry developing simulation frameworks. Over time, mostly as a result of my association with Django, I've become more involved in building web services. Shabda: How did you get started with Django? What areas of Django have you contributed to? Russell: I've … -
Popularizing Django -- Or Reusable apps considered harmful.
For all its technical merits, Django is still a very niche technology. It is my belief that the thing which is holding Django back the most, is due to one of its strengths. Making reusable apps is easy and simple in Django. In Django this is the correct way to do things. You take a few apps, mix them together in your project, and deploy to start your site. Compare the installation steps of Wordpress and an imaginary blog software better than Wordpress called Djangopress. Wordpress FTP wordpress to webserver. Point browser to site.com/blog Next-Next-Next done. Djangopress Svn checkout Djangopress Svn checkout django-registration Svn checkout other Django apps Djangopress depends on. Maybe django-mptt, django-threadedcomments or a few others. Edit your settings.py to add all these apps to INSTALLED_APPS. Add database settings, and other changes if needed. Telnet to your server and do syncdb Create templates. Done. This does not take into account the extra hoops Apache makes you jump through, compared to using a PHP app. How I got started with web programming. I wanted to run a forum. PhpBB was free, and seemed most widely used. Installed it, and wanted to tinker with it, so learnt Php. If there … -
An interview with Michael Trier
Michael Trier is a long time Django user and evangelist. He has worked with a number of technologies including Rails and .net. His insights on marketing Django to traditionally Enterprisy areas were extremely informative. He produces TWiD, along with Brian Rosner which is great to keep abreast of the latest happenings in the Django community. He graciously agreed to be interviewed by the 42topics blog. Shabda: Would you tell a little about yourself, how did you get started with Django, what other projects have you used or are associated with? Michael: Well, I've been programming ever since I can remember, probably around 11 years old. I grew up in Silicon Valley, and that whole story is a pretty interesting one. I did the usual thing of starting out with languages like ASM, C, C++ , Pascal. Moved on to things like Delphi, VB, and most recently I spent quite a bit of time with Ruby, Rails, and within the past year and a half dabbling with Django. I came to Django for a particular reason. I was focussed on building a high content push type of site and it just seemed like Django was a much better fit for that … -
An Interview with Jacob Kaplan-Moss - Creator of Django
Jacob Kaplan-Moss is the co-creator of Django along with Adrian Holovaty, as well as the author of the Django Book. He has been involved with Django since before it was called Django. He is currently employed at Whiskey Media where his job is hacking at Django. He blogs on Jacobian.org. He graciously agreed to be interviewed at the 42topics blog. Shabda: Would you tell a little about yourself? How did you get started with Django? What other software/applications have you worked with. (Both OSS and otherwise)? Jacob: So a bit about me: I grew up in Silicon Valley, so like many other geeks I got started with computers really early; I was programming professionally before I graduated high school. I didn't start out doing web development; in college I worked on video surveillance systems for airports, harbors, marinas, and highways. That's where I found Python: I rewrote a Java-based camera controller in Python and haven't looked back since. I started doing web development pretty seriously when I moved to New York and took a job for a design firm there. The job was pretty terrible, and the technologies were worse: the good sites were PHP, and there was a bunch … -
An Interview with Adrian Holovaty - Creator of Django
Adrian Holovaty is the co-creator of Django, author of the Django book and is currently the BDFL of Django along with Jacob Kaplan-Moss. He studied journalism at University of Missouri–Columbia and has worked with many news sites including Lawrence Journal World and Washington Post. He currently works at EveryBlock, a startup he founded. Shabda: Would you tell a little about yourself? You majored in Journalism, how did you move to Programming? Adrian: Sure! I have a dual background in journalism and computer science. I intended to get a degree in journalism and a minor in computer science, but things got a little off track. I heard from a professional colleague that a certain Web site would probably hire me if I graduated a semester early, so I hurriedly dropped my CS minor and got special permission to graduate early -- but once the time came to ask for that job, the company was in the middle of a hiring freeze and didn't have a position for me. So, in hindsight, I should've stuck with the minor, but things ended up working out OK. Because journalism and computer science don't normally go together, I've had some success in this silly little … -
Develop Twitter API application in django and deploy on Google App Engine
Twitter's robust REST API enables building of good applications that leverage its increasingly large and real-time data. Google's cloud system App Engine not only provides a scalable platform for deploying applications, but also proves to be economically viable because of its pay per resource usage model and a large free quota. Little wonder then, there are increasingly large number of twitter apps being deployed on App Engine. In this post, I am going to examine how to create a simple application based on twitter's REST API and deploy it on Google App Engine. A deployed version can be found on Twitter-Follow. The specification is simple. It finds if a twitter user is following another twitter user, given their user names. The application is developed using django and deployed on Appengine using the app engine patch project. The code is open sourced with GPL v3 and can be checked out from Google Code. Lets get started building this application. Create an application Create a new application from App Engine Dashboard by registering an unique appspot.com sub-domain. This will be your application's unique identifier. You may have to register first. Install App Engine SDK Download and install the App Engine SDK. There … -
Better Python package management using source and version control systems
Thanks to awesome django community, there is plenty of open source django code around. These packages get updated quite often and if you use it often like we do, you'd have possibly realized the need to manage these packages better. Thankfully, all python ever needs is the source, and all you need to do is to place the source in the python path. Most projects use Distributed Version Control Systems like Mercurial and Git, and they come locally with the entire history of the source which provides a lot of control to use any version of the code. For code that we use often, like django packages, using the source from a version control system seems to be the best way to manage. In order to install django-registration, a popular django app by James Bennett, you need to: Clone the repository: $ hg clone https://becomingguru@bitbucket.org/ubernostrum/django-registration/ django_registration Create a symbolic link in the python path: $ sudo ln -fs ~/django_registration/registration /usr/lib/python2.6/dist-packages/django_registration Thats it. django_registration is now on the python path, courtesy of symbollic link, that links the django-registration source to python path, in this case the dist-packages/ folder; thus it will be possible to import this app within the python environment. … -
Django Request Response processing
Have you wondered the steps a users request goes through before being responded to by Django? The answer lies in reading django.core.handlers.base and django.core.handlers.wsgi. Here is a diagram explaining what happens. (Click to enlarge.) The steps are. (With Apache/Mod_wsgi, similar steps for other setup.) User's request comes to Apache etc. Apache sends request to django.core.handlers.wsgi via mod_wsgi. A list of request and response middleware callables is created. Request middleware is applied. If it sends a response, it is returned to the user. urlresolvers.resolve finds the view funcion to use. View middleware is applied. If response comes, it is sent back to the user. View function is called. It talks to models to do business logic, and renders the templates. The response middleware is applied, and response is sent back to the users. This misses a lot of important steps (Exception middleware, request_context populating, ...) but is a basic high level overview. Resources django/core/handlers/base.py django/core/handlers/wsgi.py .dia and other files for the image Do you twitter? Do you Github? Find us there. -
Remote debugging - debugging pesky server only bugs
Here is a quick tip. (Obvious if you work with Django for any length of time, but I have seen a few people who are not aware) You can put debug trace import pdb; pdb.set_trace() in your code, and put it on the server. When you access this view from your local browser, the debug is still hit and you have a debug shell on your server where you can step through. (Obviously this works only if you ran the code via manage.py runserver. But manage.py runserver start the server to listen only on local connections. If you want to access remotely you need to run as, python manage.py runserver 0.0.0.0:8000 Edit: As SmileyChris commented, a faster way is, python manage.py runserver 0:8000 The 0.0.0.0 implies that remote connections are possible. For me, this has been a lifesaver against those pesky bugs which show themselves only on the server, but not on the local machine. -
Django design patterns
This is announcement about our new work, Django design patterns, a ebook about, well, Django design patterns. (Well imagine that!). Here is the readme copied from there. [Edit] Syntax highlighting and indentation preservation were totally brroken. Fixed now. Django design patterns is a book about commonly occuring patterns in Django. Not patterns in Gof sense, but patterns in the sense, we work this way, and it works for us. For us it is a ~pattern of work~ sense. At this point this is just a lot of brain dump from us. The latest sources are always available from http://github.com/uswaretech/django-design-patterns/tree/master and latest html from http://djangodesignpatterns.uswaretech.net/ Please leave errata, feedback, critique as comments here. This is still very much a work in progress, released in the spirit of release early, release often. Click here to get it, or fork it on Github -
Aren't django signals a little like comefrom?
In computer programming, COMEFROM (or COME FROM) is an obscure control flowstructure used in some programming languages, primarily as a joke. I never liked using signals. Recently I was asked that, and has no answer, but a little thinking led me to this question. Aren't signals a little like COMEFROM. If yes, aren't they as bad as COMEFROM? If you do not know what a COMEFROM is, [wikipedia to the rescue](http://en.wikipedia.org/wiki/COMEFROM) Some hypothetical code using COMEFROM, again from wikipedia, from goto import comefrom, label comefrom .repeat name = raw_input('what is your name? ') if name: print "Hello",name label .repeat print "Goodbye!" And Some actual Django code using signals class Post(models.Model): name = models.CharField(...) ... num_comments = models.PositiveIntegerField(default = 0) class Comment(models.Model): ... post = models.ForeignKey(Post) def handle_num_comments(sender, **kwargs): instance = kwargs['instance'] instance.post.num_comments+=1 instance.post.save() from django.db.signals import post_save post_save.connect(handle_num_comments, sender=Comment) And the same code using COMEFROM class Post(models.Model): name = models.CharField(...) ... num_comments = models.PositiveIntegerField(default = 0) class Comment(models.Model): ... post = models.ForeignKey(Post) def save(self, *args, **kwargs): super(Comment, self).save(*args, **kwargs) instance = self LABEL .post_save def handle_num_comments(sender, **kwargs): instance = kwargs['instance'] COMEFROM .post_save instance.post.num_comments+=1 instance.post.save() So isn't the signals code a little like COMEFROM, and why is it superior to COMEFROM? … -
Django aggregation tutorial
One of the new and most awaited features with Django 1.1 was aggregation. As usual, Django comes with a very comprehensive documentation for this. Here, I have tried to put this in how-to form. Jump to howtos or Get source on Github. Essentially, aggregations are nothing but a way to perform an operation on group of rows. In databases, they are represented by operators as sum, avg etc. To do these operations Django added two new methods to querysets. aggregate annotate When you are have a queryset you can do two operations on it, Operate over the rowset to get a single value from it. (Such as sum of all salaries in the rowset) Operate over the rowset to get a value for each row in the rowset via some related table. The thing to notice is that option 1, will create one row from rowset, while option 2 will not change the number of rows in the rowset. If you are into analogies, you can think that option 1 is like a reduce and option 2 is like a map. In sql terms, aggregate is a operation(SUM, AVG, MIN, MAX), without a group by, while annotate is a operation … -
A response to Dropping Django
Brandon Bloom yesterday wrote an interesting post titled dropping Django. Despite a lot of hand waving(We needed a pragmatic template language to replace Django's idealistic one.), it raises some valid questions, so here is a solution to some of them. No support for hierarchical url creation. The simplest representation of nested urls I can think of is a nested tuple. Lets represent, the urls for a simple app by, >>> tree_urls = ('', 'list', ... ('edit/', 'edit', ('auto/', 'edit_auto')), ... ('^add/', 'add'), ... ('delete/', 'delete', ('hard/', 'delete_hard')) ... ) Guess what, urls.py is just a python module which excepts a variable names urlpatterns. Which means it is very easy to write a function which converts this nested structure to flat, structure. Here is a quick attempt at that, def merge(url): full_url=[] for i, el in enumerate(url): if i%2==0: full_url.append(el) full_url = ''.join(full_url) return full_url def combineflatten(seq): items= tuple(item for item in seq if not isinstance(item, tuple)) yield items for item in seq: if isinstance(item, tuple): for yielded in combineflatten(item): yield items+yielded def generate_flat_urls(tree_urls): """ >>> tree_urls = ('', 'list', ... ('edit/', 'edit', ('auto/', 'edit_auto')), ... ('^add/', 'add'), ... ('delete/', 'delete', ('delete/', 'delete_hard')) ... ) >>> generate_flat_urls(tree_urls) [('^$', 'list'), ('^edit/$', 'edit'), … -
Django-SocialAuth - Login via twitter, facebook, openid, yahoo, google using a single app.
TL;DR version: Here is an app to allow logging in via twitter, facebook, openid, yahoo, google, which should work transparently with Django authentication system. (@login_required, User and other infrastructure work as expected.) Demo and Code.Longer version follow: We are releasing our new app. Django-Socialauth. This app makes it awfully easy, to allow users to login your site using Yahoo/Google/Twitter/Facebook/Openid. A demo is available here. This is released under an Attribution Assurance License. A copy of the same is provided included with the code. After installing this app, you can use @login_required on any view and users identified via any means can access protected content. We provide services to integrate and implement this, for a low price of USD 1600. Please contact us at licenses@uswaretech.com to discuss your exact needs. The README is copied here for convenience. What it does. Allow logging in via various providers. Logging In This is a application to enable authentication via various third party sites. In particular it allows logging in via Twitter Gmail Facebook Yahoo(Essentially openid) OpenId Libs you need to install python-openid (easy_install) python-yadis (easy_install) python-oauth(easy_install) The API Keys are available from http://www.facebook.com/developers/createapp.php https://developer.yahoo.com/dashboard/createKey.html https://www.google.com/accounts/ManageDomains http://twitter.com/oauth_clients How it works. Openid: Users need to provide … -
Django gotchas
This is announcement about our new work, Django Gotchas, a teeny tiny ebook about commonly occurring gotchas with Django. Here is the readme copied from the project. Django-gotchas is a collections of gotchas which happen commonly when you are working with Django. They are some errors which I have made commonly or seen others do, these are not the errors which happen because they are hard to reason about, these are those errors which hapen when you close your eyes for a moment when coding. This is still very much a work in progress, released in the spirit of release early, release often. Click here to get it, or fork it on Bitbucket In Other news We have slightly updated the Django design patterns, though not the public website. cyrildoussin has done a lot of changes to Socialauth and made it much better. You can get it here . Thank! We will be merging this soon. -
Writing your own template loaders
Django has three builtin template loaders which are used to get the templates for rendering. TEMPLATE_LOADERS = ( 'django.template.loaders.filesystem.load_template_source', 'django.template.loaders.app_directories.load_template_source', # 'django.template.loaders.eggs.load_template_source', ) Writing your template loader is a awfuly easy. It is a callable which Returns a tuple of (openfile, filename) if it can find the template. Raise TemplateDoesNotExist if the templates cannot be found. The simplest template loader can be from django.template import TemplateDoesNotExist def load_template_source(template_name, template_dirs=None): try: return open(template_name).read(), template_name except IOError: raise TemplateDoesNotExist, template_name if you put this to your template loaders directory, TEMPLATE_LOADERS = ( 'django.template.loaders.filesystem.load_template_source', 'django.template.loaders.app_directories.load_template_source', 'dgrid.load_template_source' # 'django.template.loaders.eggs.load_template_source', You can do access a template using an absolute path. In [6]: get_template('/home/shabda/abc.txt') Out[6]: <django.template.Template object at 0x91c860c> In [7]: temp = get_template('/home/shabda/abc.txt') In [8]: temp Out[8]: <django.template.Template object at 0x9358a0c> In [9]: temp.render Out[9]: <bound method Template.render of <django.template.Template object at 0x9358a0c>> This is the first in the series of short and sweet Django posts we are going to do. You are interested, right. Do follow us on twitter or subscribe to our feed. We build Amazing We Apps. Talk to us or email us at sales@uswaretech.com . -
Django for a Rails Developer
This is not yet another Django vs Rails blog post. It is a compilation of notes I made working with Django after having worked on Rails for years. In this post I want to give a brief introduction to Django project layout from a Rails developer point of view, on what is there, what is not there and where to look for things. It should help a rails developer working on django be able to find the necessary files and underatnd the layout of the project files. Once you have both the frameworks installed on your system you can create the projects using the commands # creating a rails project rails rails_project # creating a Django project django-admin.py startproject django_project Lets look at the files and structure created by the respective frameworks #rails_project README Rakefile app/ controllers/ application_controller.rb helpers/ application_helper.rb models/ views/ layouts/ config/ boot.rb database.yml environment.rb environments/ development.rb production.rb test.rb initializers/ backtrace_silencers.rb inflections.rb mime_types.rb new_rails_defaults.rb session_store.rb locales/ en.yml routes.rb db/ seeds.rb doc/ README_FOR_APP lib/ tasks/ log/ development.log production.log server.log test.log public/ 404.html 422.html 500.html favicon.ico images/ rails.png index.html javascripts/ application.js controls.js dragdrop.js effects.js prototype.js robots.txt stylesheets/ script/ about console dbconsole destroy generate performance/ benchmarker profiler plugin runner server test/ … -
Django quiz
A quick django quiz. Answers available tomorrow. Get it as a text file (django-quiz) or on google docs or read below. ### Easy 1. You have a class defined as class Post(models.Model): name = models.CharField(max_length=100) is_active = models.BooleanField(default=False) You create multiple objects of this type. If you do Post.objects.get(is_active=False), what exceptions is raised? a. MultipleObjectsReturned b. ManyObjectsReturned c. SyntaxError d. MultipleModelReturned e. ManyModelReturned 2. Where is the function render_to_response defined? a. django.views b. django.shortcuts c. django.templates d. django.contrib.templates e. django.contrib.shortcuts 3. What is the default name for the table created for model named Post in application blog a. post_blog b. blog_post c. postblog d. blogpost e. Postblog 4. How do you send a 302 redirect using django? a. return HttpRedirectResponse() b. return HttpResponseRedirect() c. return HttpRedirectResponse(permanent=True) d. return HttpResponseRedirect(permanent=True) e. return HttpRedirectResponse 5. In django.contrib.auth, Users passwords are kept in what form? a. Plain text b. Hashed c. Encrypted d. Hashed then encrypted 3. Encrypted then hashed 6. Which of the following is correct way to find out if a request uses HTTP POST method? a. request.is_post() == True b. request.METHOD == 'post' c. request.METHOD == 'POST' d. request.method == 'post' e. request.method == 'POST' 7. Generic views have access … -
Python metaclasses and how Django uses them
Foss.in is without doubt India's largest FOSS technology conference. Lakshman gave a talk today on "Python metaclasses and how Django uses them". Here are the slides from that talk. Doing magic with python metaclassesView more documents from Usware Technologies. [Edit] Some reactions, http://twitter.com/jaideep2588/status/6295483833 http://twitter.com/kunalbharati/status/6296572939 And the talk images, http://twitpic.com/rxhn7 You should follow us on twitter and Subscribe to our blog