Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Testing App Views
First of all, thanks to those people who've been reading and pointing out improvements in the comments - it's much appreciated, and I've learned a lot from you! Django applications tend to have views, in a views.py file. These are generally looked up by URL. URLConfs (various urls.py files) are used to map request URLs to views. This can lead to a problem from a testing perspective. Not all applications have urls.py files; and for those that do, there's nothing stopping a project wiring up different URLs to those views through a custom urls.py. It therefore becomes difficult to use Django's test client to invoke a view using a GET or a POST because you don't know how that URL has been configured. After all, you run python manage.py test from your project, and the project's configuration is used. Let's say I have a views.py that looks like this: from django.shortcuts import render_to_responsefrom django.template import RequestContextdef say_hi(request): return render_to_response('app/hi.html', context=RequestContext(request)) I want to use Django's test client to ensure that when this view is called, it returns an HTTP 200 OK response. However, my app doesn't have a urls.py - the person using it is meant to wire this view … -
Testing App Views
First of all, thanks to those people who've been reading and pointing out improvements in the comments - it's much appreciated, and I've learned a lot from you! Django applications tend to have views, in a views.py file. These are generally looked up by URL. URLConfs (various urls.py files) are used to map request URLs to views. This can lead to a problem from a testing perspective. Not all applications have urls.py files; and for those that do, there's nothing stopping a project wiring up different URLs to those views through a custom urls.py. It therefore becomes difficult to use Django's test client to invoke a view using a GET or a POST because you don't know how that URL has been configured. After all, you run python manage.py test from your project, and the project's configuration is used. Let's say I have a views.py that looks like this: from django.shortcuts import render_to_responsefrom django.template import RequestContextdef say_hi(request): return render_to_response('app/hi.html', context=RequestContext(request)) I want to use Django's test client to ensure that when this view is called, it returns an HTTP 200 OK response. However, my app doesn't have a urls.py - the person using it is meant to wire this view … -
Testing App Views
First of all, thanks to those people who've been reading and pointing out improvements in the comments - it's much appreciated, and I've learned a lot from you! Django applications tend to have views, in a views.py file. These are generally looked up by URL. URLConfs (various urls.py files) are used to map request URLs to views. This can lead to a problem from a testing perspective. Not all applications have urls.py files; and for those that do, there's nothing stopping a project wiring up different URLs to those views through a custom urls.py. It therefore becomes difficult to use Django's test client to invoke a view using a GET or a POST because you don't know how that URL has been configured. After all, you run python manage.py test from your project, and the project's configuration is used. Let's say I have a views.py that looks like this: from django.shortcuts import render_to_responsefrom django.template import RequestContextdef say_hi(request): return render_to_response('app/hi.html', context=RequestContext(request)) I want to use Django's test client to ensure that when this view is called, it returns an HTTP 200 OK response. However, my app doesn't have a urls.py - the person using it is meant to wire this view … -
Django moving toward 1.0: tickets overview
As the Django web framework (see our previous study comparing 3 major web frameworks) is moving toward the 1.0 release (due in early september this year), one of the creators of Django, Adrian Holovaty, asked about the strength and weekness of Django replied: I love the way URLconfs work — like a table of contents [...] -
Time to release: django-digest and django-oauthsp
Let me be clear on this: altough I'm already using this code in byNotes, I still consider it in alpha stage, so think twice before incorporating it into your project. django-digest is an app for helping with digest authentication. It implements the basic models needed for storing the data, while authentication is handle by wapi middleware. On the other hand, django-oauthsp implements the service provider side of OAuth with all the bells and whistles. Currently, it supports the full OAuth spec, custom token attributes, token renewal as specified by ScalableOAuth and problem reporting as specified by ProblemReporting. It also includes some views for requesting, authorizing, reviewing and revoking user tokens as well as registering, editing and listing consumers. If you try this apps, you know, leave some feedback in the comments ;). -
Django
Django -
Odds and Ends
I’ve been busy. -
Ajax with dojango (dojo+django)
Ok, now you got dojango and you want to write an AJAX app. There are some basics that just need to be provided in order to make that a piece of cake. Dojango offers them. And this article will show you how to best plug those pieces together and get up and running with ajax and dojango. This article will show you how to simply pass data properly from the backend to the client. JSON communication with the server There are enough use cases (and they are becoming more) when you want to get data from the server and the most common data format nowadays for that is JSON, for various good reasons. Let’s construct a simple form who’s data we want to submit to the server and know if it all went ok or not. For now we just print the submitted data on the django console (from where you started the local dev server) and we let the user know about the submission with the small text “Submitted” beside the submit button. So let’s get started with the JavaScript side. Dojango luckily provides us with the basic infrastructure, so let’s create a template that extends dojango/base.html (it is … -
Flexible test-database engine selection in Django
StopFinder has a suite of unit and integration tests that probably has just about as much code as the application itself. The first thing I do after the deployment is run the tests. This is in the nature of a smoke test, to make sure that I haven’t messed up syncing with third-party libraries and [...] -
MySQL Connection Pooling with Django and SQLAlchemy
Here's a quick and dirty recipe to get connection caching from SQLAlchemy. This is really not connection pooling as that would require a separate process to only handle connections. All this does is prevent the connection from closing after you finish a query. We're also not replacing the Django ORM. To give a little more background, normally when you use Django to get to your database, Django will automatically disconnect from the database when the thread is done with that query. So, if you do something like: q = Model.objects.all() As soon as you destroy "q" it will close the database connection. This is not ideal as it takes time to connect to the database and then to release the database connection. To prevent this, you can use SQLAlchemy to cache the connections for you. With SQLAlchemy, when "q" is destroyed the database connection is not closed. The database connection is only closed when the process running Python is closed. If you have your web server killing threads that are idle then you still have a problem, but you should be avoiding this anyway. See my previous blog post for details about thread thrashing. Step 1 - Install SQL Alchemy: … -
How to evaluate the coverage of a django test suite
I am using this recipe to estimate the coverage of the test suites arounds my django's projects.Software PrerequisitesIn order to follow this recipe you will need to have the following software installed :Djangopython (obviously)coverage.pyI will not explain how to get the first 2 items of this list installed since if you are reading this I am assuming that you are familiar with them. "Coverage" is a bit different, python package index make installing this component a piece of cake.# easy_install coverageUsage of coverage with django test suiteThis presentation give a recipe to evaluate the coverage of your test suite. I found this page useful to understand how to use it. If you are looking for a project to test this recipe on you can checkout "django-survey". The 3 lines below is all you need to get a report on the coverage of your test suite.# coverage.py -e (1)# coverage.py -x manage.py test survey (2)# coverage.py -r -m >report.txt (3)The first line erases collected coverage data, the second executes the module and collect the coverage data, the third line reports on the statement coverage for the given files and show line numbers of the statements that weren't executed.Then you need to … -
Javascript and special characters
I just found a website providing tools and information about javascript and special characters. My current problem was that I lost the special characters in an ajax call. Some trying later and it finally worked - check it out: http://www.the-art-of-web.com/javascript/escape/ -
Javascript and special characters
I just found a website providing tools and information about javascript and special characters. My current problem was that I lost the special characters in an ajax call. Some trying later and it finally worked - check it out: http://www.the-art-of-web.com/javascript/escape/ -
Javascript and special characters
I just found a website providing tools and information about javascript and special characters. My current problem was that I lost the special characters in an ajax call. Some trying later and it finally worked - check it out: http://www.the-art-of-web.com/javascript/escape/ -
Dojango version 0.3 released
Now it is official! We released Dojango on google code today and you can get details about it and download it from there. Dojango provides a dojo integration as a reusable app. Download it, copy it into your django project and you have dojo included into django. A quick summary of the main features of dojango: a reusable django app that provides dojo easy dojo setup inside django build an optimized dojo some helper functions, i.e. JSON conversion switch easily between different dojo versions. The main purpose of dojango is to help you using dojo within your django projects. Currently it delivers the main infrastructure to easily switch between several dojo versions and includes several functions that helps developing rich internet applications. Now we are able to chain dojo and django on a solid basis and we work at porting the actual django form widgets to use dojo widgets. We would be happy, if a lot of people would test the current version and tell us about bugs, strange behaviors, misunderstandings, … Also we are open for everyone who would like to help out extending dojango. In coincidence Roberto Saccon (big thanks!) already testet dojango with google app engine and … -
How I Moved My Commercial Projects to Newforms-Admin
My projects were all running on an SVN checkout from late April 2007, after the Queryset-refactor branch was merged into trunk. This meant that I had to make a number of changes, on a public server, to incorporate modifications to file uploads, generic create/update views, and more. In this post I'm only going to cover how I did the change to Newforms Admin, as the other changes were relatively simple for my projects. I made these changes on a live server, whilst my projects were running. For the volume of changes I had to make, this was very straightforward. I use FastCGI, and because the FastCGI processes were already running I was able to modify the Python code without it taking effect until I restarted FastCGI. As always, make sure you've got a backup that's easy to roll back to. The first thing I did was create my admin.py files in each application. For example, for DjangoSites I removed this admin definition from my 'Website' model: class Admin: list_filter = ('verified', 'screenshot',) list_display = ('url', 'title', 'owner', 'created', 'verified', ) search_fields = ('title',) and moved it into websites/admin.py: from django.contrib import admin from djangosites.websites.models import Website class WebsiteAdmin(admin.ModelAdmin): list_filter = … -
How I Moved My Commercial Projects to Newforms-Admin
My projects were all running on an SVN checkout from late April 2007, after the Queryset-refactor branch was merged into trunk. This meant that I had to make a number of changes, on a public server, to incorporate modifications to file uploads, generic create/update views, and more. In this … -
Django-treemenus new release 0.5
I have just packaged a new release 0.5 for django-treemenus That release should only concern people working on Django’s development version after the merge of the newforms-admin branch. I also hear that Django 1.0 alpha has just been released, so that’s good timing ;) If you’re using Django’s trunk prior the NFA merge, then you can stick to 0.4. I’ve also included the German translation kindly provided by Thomas Kerpe (thanks Thomas!). Available languages are now: English, French, Dutch, Russian and German. Please keep sending me your translations and they will be included in future releases. Also, I’d be very interested to hear testimonials of people using this app. How do you use it? Do you use the menu extension mechanism? How would you like to see this app improved? Any feedback/criticism is very welcome ;) -
Django tip: Translating your application names (app_label)
This MUST be a common issue for international developers: We use some geeky English name for our application and afterwards find that the translated admin index looks a little silly in the eyes of our native speaking users. Apparently a … Continue reading → -
Changeset 7967: NFA Branch Merged into Trunk
I and a host of other folks have been waiting anxiously for this merge for a while now. Excited to see it happen tonight. Good job, Brian Rosner et al. -
Changeset 7967: NFA Branch Merged into Trunk
I and a host of other folks have been waiting anxiously for this merge for a while now. Excited to see it happen tonight. Good job, Brian Rosner et al. -
Duże zmiany w django
Django idzie dużymi krokami do przodu. Coraz większe zmiany zachodzą w głównym repozytorium. Niedawno pojawił się tam patch o nazwie Large streaming uploads, czyli możliwość użycia Django do wysyłania bardzo dużych plików, które bezpośrednio, podczas wysyłania, mogą być zapisywane... -
GitHub Enables Markdown Documentation
I have been desiring to have the documentation that I write for my various projects on GitHub render to HTML when using a .markdown extension, just like they support doing for special files like README.markdown. At first, I thought they'd eventually get around to it and that is the best I could hope for as surely they are too busy to respond to a non-paying customer like me. Then I learned they the used the Lighthouse ticket system to manage their project and took public submissions for features. Before logging a feature request I did some searching and found a ticket already out there requesting exactly this same feature that I wanted. So I just added my own comments to the ticket to give it a +1. After a little back and forth I learned it was implemented tonight (just a week after my first comment). Good to see such responsive development. An example of this feature can be found in my django-aws project which is simple app to provide some template tags to provide Amazon Web Services information a la boto. -
GitHub Enables Markdown Documentation
I have been desiring to have the documentation that I write for my various projects on GitHub render to HTML when using a .markdown extension, just like they support doing for special files like README.markdown. At first, I thought they'd eventually get around to it and that is the best I could hope for as surely they are too busy to respond to a non-paying customer like me. Then I learned they the used the Lighthouse ticket system to manage their project and took public submissions for features. Before logging a feature request I did some searching and found a ticket already out there requesting exactly this same feature that I wanted. So I just added my own comments to the ticket to give it a +1. After a little back and forth I learned it was implemented tonight (just a week after my first comment). Good to see such responsive development. An example of this feature can be found in my django-aws project which is simple app to provide some template tags to provide Amazon Web Services information a la boto. -
Django auto-translation of field values
What’s really nice in Django is the gettext implementation and the _ convention. But when running django-admin.py makemessages we’re not generating any translations for dynamic values such as field values. So let’s say that we have a model and we’d … Continue reading →