Django community: Community blog posts RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Webinar: Testing Client-Side Applications with Django
Technical Director Mark Lavin will be hosting a free O’Reilly webinar today at 4PM EST or 1PM PT on Testing Client-Side Applications with Django. Mark says testing is one of the most popular question topics he receives. It’s also a topic near and dear to Caktus’ quality-loving heart. Mark’s last webinar garnered more than 500 viewers, so sign up quick! Here’s a description from Mark: During the session we'll examine a simple REST API with Django connected to a single page application built with Backbone. We'll look at some of the tools available to test the application with both Javascript unit tests and integration tests written in Python. We'll also look at how to organize them in a sane way for your project workflow. To sign up, visit the webinar page on O’Reilly’s site. -
Webinar: Testing Client-Side Applications with Django
Technical Director Mark Lavin will be hosting a free O’Reilly webinar today at 4PM EST or 1PM PT on Testing Client-Side Applications with Django. Mark says testing is one of the most popular question topics he receives. It’s also a topic near and dear to Caktus’ quality-loving heart. Mark’s last webinar garnered more than 500 viewers, so sign up quick! Here’s a description from Mark: During the session we'll examine a simple REST API with Django connected to a single page application built with Backbone. We'll look at some of the tools available to test the application with both Javascript unit tests and integration tests written in Python. We'll also look at how to organize them in a sane way for your project workflow. To sign up, visit the webinar page on O’Reilly’s site. -
Self-Hosted Server Status Page with Uptime Robot, S3, and Upscuits
For quite a while I've had a public "Status" page online for WhisperGifts via Pingdom. It basically just shows uptime over the past few days, but given my site is relatively low-volume and not ovely critical to my customers, the $10/month for Pingdom was actually one of my largest expenses after hosting. So, I started looking for an alternative. Today I re-deployed the WhisperGifts Status Page using a combination of Uptime Robot, Upscuits and Amazon S3. In short, I have Uptime Robot checking the uptime of my site (including it's subsites, such as the admin and user pages). The statistics are gathered and presented by Upscuits, which is entirely client-side JavaScript hosted on S3. My basic todo list for next time: Sign up for Uptime Robot. I'd been using them for ages on their Free plan as a backup to Pingdom; this gives 5-minute checks. Their paid plan gives 1-minute resolution. Add your sites, make sure they're being monitored correct. On the Uptime Robot dashboard, click My Settings. Open the section labelled Monitor-Specific API Keys and search for your Monitor. Copy the API key to a text file for later; repeat this step for subsequent monitors you want to include … -
Self-Hosted Server Status Page with Uptime Robot, S3, and Upscuits
For quite a while I've had a public "Status" page online for WhisperGifts via Pingdom. It basically just shows uptime over the past few days, but given my site is relatively low-volume and not ovely critical to my customers, the $10/month for Pingdom was actually one of my largest expenses after hosting. So, I started looking for an alternative. Today I re-deployed the WhisperGifts Status Page using a combination of Uptime Robot, Upscuits and Amazon S3. In short, I have Uptime Robot checking the uptime of my site (including it's subsites, such as the admin and user pages). The statistics are gathered and presented by Upscuits, which is entirely client-side JavaScript hosted on S3. My basic todo list for next time: Sign up for Uptime Robot. I'd been using them for ages on their Free plan as a backup to Pingdom; this gives 5-minute checks. Their paid plan gives 1-minute resolution. Add your sites, make sure they're being monitored correct. On the Uptime Robot dashboard, click My Settings. Open the section labelled Monitor-Specific API Keys and search for your Monitor. Copy the API key to a text file for later; repeat this step for subsequent monitors you want to include … -
Self-Hosted Server Status Page with Uptime Robot, S3, and Upscuits
For quite a while I've had a public "Status" page online for WhisperGifts via Pingdom. It basically just shows uptime over the past few days, but given my site is relatively low-volume and not ovely critical to my customers, the $10/month for Pingdom was actually one of my largest expenses after hosting. So, I started looking for an alternative. Today I re-deployed the WhisperGifts Status Page using a combination of Uptime Robot, Upscuits and Amazon S3. In short, I have Uptime Robot checking the uptime of my site (including it's subsites, such as the admin and user pages). The statistics are gathered and presented by Upscuits, which is entirely client-side JavaScript hosted on S3. My basic todo list for next time: Sign up for Uptime Robot. I'd been using them for ages on their Free plan as a backup to Pingdom; this gives 5-minute checks. Their paid plan gives 1-minute resolution. Add your sites, make sure they're being monitored correct. On the Uptime Robot dashboard, click My Settings. Open the section labelled Monitor-Specific API Keys and search for your Monitor. Copy the API key to a text file for later; repeat this step for subsequent monitors you want to include … -
Self-Hosted Server Status Page with Uptime Robot, S3, and Upscuits
For quite a while I've had a public "Status" page online for WhisperGifts via Pingdom. It basically just shows uptime over the past few days, but given my site is relatively low-volume and not ovely critical to my customers, the $10/month for Pingdom was actually one of my largest … -
Building Django proxies and MUD libraries
2015 is here and there is a lot of activity going on in Evennia's repository, mailing list and IRC channel right now, with plenty of people asking questions and starting to use the system to build online games.We get newcomers of all kinds, from experienced coders wanting to migrate from other code bases to newbies who are well versed in mudding but who aim to use Evennia for learning Python. At the moment the types of games planned or under development seems rather evenly distributed between RPI-style MUDs and MUSH games (maybe with a little dominance of MUSH) but there are also a couple of hack-and-slash concepts thrown into the mix. We also get some really wild concepts pitched to us now and then. What final games actually comes of it, who can tell, but people are certainly getting their MU*-creative urges scratched in greater numbers, which is a good sign. Since Christmas our "devel" branch is visible online and is teeming with activity. So I thought I'd post an summary about it in this blog. The more detailed technical details for active developers can be found on Evennia's mailing list here (note that full docs are not yet written … -
Mirroring my article on Chennai 36 – The Alumni Blog of IITM
Recently, I wrote an article to Chennai36 which is a blog maintained by the Alumni Association of IITM. The article was about my opinions on how to apply to graduate school for an undergrad at IITM. In this post, I am mirroring that article on this blog. The original article can be found here. ——————————————————————————————————————————————————— The Grad Guru : Karthik Abinav at University of Maryland, College Park Note : Whenever I mean grad school, I am going to be referring to a PhD program. Though most of this advice also applies to MS programs, you should bear in mind that my focus is on PhD program. Since, I do not have much knowledge about the MS programs, I will not comment much about them in this article. 1. Please tell us about yourself, the university you are studying at, the research field you are working on, and the scope it has to offer after an MS or PhD. Also tell us about a typical day in the life of a postgraduate student. I recently started my PhD in Computer Science at University of Maryland at College Park. I am broadly interested in theoretical computer science. At a high level, … -
Installation of PhoneGap on Debian system
I have recently been developing an application for IOS using phonegap. I was extremely fascinated by the simplicity of its usage. In this post, I will guide through a step-by-step procedure to setup phone gap on a Debian system. Setting Up PhoneGap application on a local system You will come across the term Cordova often when one talks about PhoneGap. Please note that for most purposes, both are essentially interchangeable. Here, I will give instructions to setup cordova on a Linux Debian system. You can make appropriate modifications for your operating system. The first step is to install the latest version of cordova on your system. The installation using the Command-Line Interface is extremely straight forward. 1) Install NodeJS on your system from their website. 2) Run the following to install cordova sudo npm install -g cordova 3) Once cordova is installed, now create a new project. To do that run the following command sudo cordova create photoFilter com.photoFilter.filter photoFilter Note: I am calling my example application as photoFilter. This will create folder called photoFilter in the current directory. The important files to note here are the config.xml file and the www folder. The config.xml file is where you will … -
Mercurial Mirror For Django 1.8 Branch
Another year, another alpha release for Django and … another “production” mirror for me and anybody else interested. Django has just released the first alpha for Django-1.8. As usual, I create the mirror as soon as the corresponding branch is opened (stable/1.8.x), but this is still alpha stuff for you to test, not anything stable you […] -
Importing your old comments to Disqus site
In one of my latest blogpost on disqus I covered topics on integrating Disqus to the website and disqus SSO. In this post, I will let you know how to migrate the older comments to Disqus. If you sneak peek in to the alluring features of disqus you may make your mind to migrate your custom commenting system on your blog to use disqus commenting system. The threaded comments and replies, powerful moderation and admin tools, RSS options and many more features come in as battaries included with Disqus which makes the commenting more interactive and easy to deal with. Let us kick start the process. Till date importing the old comments directly from the blogger and wordpress to disqus is feasible. This can be achieved by using tools and plugins that are already existing in them and its pretty straight forward. In this post our prime concern will be laid on custom XML import format. If you are using neither blogger, nor wordpress the custom XML import format which is based on the WXR (WordPress eXtended RSS) schema comes to the rescue. Disqus also supports MovableType, and IntenseDebate but preferably WXR is of more concern. I consider a case … -
SSL broken in gevent on Python 2.7.9 – a debugging tale of woe
I thought it would be worth writing this up quickly as a blog post, just so it’s documented, though I’m guessing the bug is common knowledge by now. The process of finding out the issue was (eventually) enlightening for me though, especially how far the initial problem was from the bug. I was having problems last week deploying changes to one of our projects hosted on Heroku. I’d done a full run-down of dependencies trying to bring in security and bug fixes, making everything Python 2.7 and Ubuntu Trusty compatible (or, for Heroku, cedar-14 stack compatible). Everything worked fine locally, even using foreman (which is the Heroku tool that runs your code as if it was deployed on Heroku—in this case running through gunicorn with gevent). However, on deploying to a clean app and database on Heroku, the Persona Single-Sign-On authentication wasn’t working. The project’s settings are slightly involved, but the fact the admin site was working and I was getting a login page at all indicated that things were probably okay on the Django side of things. Persona itself worked fine locally, as well as on stage and production deployments on Heroku. I suspected DNS issues, but this turned … -
VariableDoesNotExist: Failed lookup for key [text] in 'None'
VariableDoesNotExist: Failed lookup for key [text] in 'None', that was the error that I got out of an internal django app that I wrote. The app is the most error-free one that I ever build, so I was quite surprised. I was even more surprised when I started debugging it. The error was in the search functionality. Searching for "lizard" would give an "error 500" page. Searching for "lizar" gave 0 results (which is fine), for "lizardd", too. "lidard" also gave 0 results. Only a search for "lizard" crashed the site. Huh? Weird. I got the question whether I put a hidden message into this app (as "lizard" is one of our main products) :-) Locally it all worked fine, of course. Only on the server did I see the error. Here's the relevant part of the traceback: Stacktrace (most recent call last): File "django/core/handlers/base.py", line 112, in get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "haystack/views.py", line 50, in __call__ return self.create_response() File "haystack/views.py", line 144, in create_response return render_to_response(self.template, context, context_instance=self.context_class(self.request)) File "django/shortcuts/__init__.py", line 29, in render_to_response return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs) File "django/template/loader.py", line 169, in render_to_string return t.render(context_instance) File "django/template/base.py", line 140, in render return self._render(context) ... File … -
New emacs setup
I edit all my code with emacs. Since 1996 or so. And all blog entries. And all... So my emacs settings are "quite important" to me. When I installed the new laptop I'm typing this on, my settings stopped working: I just deleted my ~/.emacs.d/ directory because I wanted to upgrade my setup. Since a couple of years I used the emacs starter kit version 2. The link goes to my slightly modified copy of the original version 2 starter kit. The setup change I wanted to make was to update to the version 3 of the emacs starter kit. That link goes to the real starter kit, which in version 3 is... just a text document! Which is a good thing. You don't need to clone a git repo just to get a bunch of settings. You use emacs' package tool to download the better-defaults package, which contains most/all of the settings changes that made the original emacs starter git such a joy to use. And on top of that, it suggests a couple of handy packages to use also. I'm using all of the suggested ones (apart from 'scpaste', which I don't use). And it provides a template … -
Actually doing work - proof by blogging
I'm a programmer. Which means it is not always clear when I'm working. What I mean is that, if I'm sitting behind my screen, I might be reading an article about postgres performance improvements, but I might also be reading the news. And clicking on my ipad might mean I'm keeping my python knowledge up to date by reading weblogs, but I might also be reading some comics. Typing furiously on my keyboard might indicate great productivity, but it also might indicate a long personal email. The other way around, sitting nicely in the living room at home, clicking away on the laptop, might mean I'm relaxing by writing an update on my model railway work on a forum, but it might also mean I'm finishing off a work project in my own time. "Doing research" is a potential problem for me. I've spend a ton of time reading about Ansible and on how to use it. But it was only when I actually started doing something with it that I started to wrap my head around it. So... just reading and thinking is dangerous to my productivity. I want to be productive. One of the simplest tricks I can … -
Updated instructions to fix macbook pro with black screen
Last week I wrote about my macbook pro and its screen that suddenly stayed black after waking it from sleep. Including instructions on how to fix it. I now have improved instructions... The piece of crap did it again. (This time there was no external monitor in play, btw) Symptoms: you open up your late 2014 macbook pro 15" and expect it to wake from sleep in 0.5 seconds. Instead the screen stays black. Press shift-option-control-power and release them all at the same time. This resets the "system management controller", amongst others it makes sure the "power" button actually reacts. Now look at the back of your mac's screen. Make sure the light of the apple logo is off. If necessary, keep the power button pressed for 5 seconds to force a shutdown. (The power button should work again after step 1). Keep your fingers ready for pressing command-option-p-r at the same time. You need both hands for this weird combination. Press the power button and then hold these four keys. Your mac will now actually boot, give you the startup sound and lo and behold, you've got your screen back. I do hope apple will fix this Real Soon. … -
Proxying objects in Python
A lazy object proxy is an object that wraps a callable but defers the call until the object is actually required, and caches the result of said call. These kinds of objects are useful in resolving various dependency issues, few examples: Objects that need to held circular references at each other, but at different stages. To instantiate object Foo you need an instance of Bar. Instance of Bar needs an instance of Foo in some of it methods (but not at construction). Circular imports sound familiar? Performance sensitive code. You don't know ahead of time what you're going to use but you don't want to pay for allocating all the resources at the start as you usually need just few of them. There are other examples, I've just made up a couple for context. If you've used Django you may be familiar with SimpleLazyObject. For simple use-cases it's fine, and if you're already using Django the choice is obvious. Unfortunately it's missing many magic methods, most glaring omissions: __iter__, __getslice__, __call__ etc. It's not too bad, you can just subclass and add them yourself. But what if you need to have __getattr__? The horrors of the infinite recursive call beckon. … -
Proxying objects in Python
A lazy object proxy is an object that wraps a callable but defers the call until the object is actually required, and caches the result of said call. These kinds of objects are useful in resolving various dependency issues, few examples: Objects that need to held circular references at each other, but at different stages. To instantiate object Foo you need an instance of Bar. Instance of Bar needs an instance of Foo in some of it methods (but not at construction). Circular imports sound familiar? Performance sensitive code. You don't know ahead of time what you're going to use but you don't want to pay for allocating all the resources at the start as you usually need just few of them. There are other examples, I've just made up a couple for context. If you've used Django you may be familiar with SimpleLazyObject. For simple use-cases it's fine, and if you're already using Django the choice is obvious. Unfortunately it's missing many magic methods, most glaring omissions: __iter__, __getslice__, __call__ etc. It's not too bad, you can just subclass and add them yourself. But what if you need to have __getattr__? The horrors of the infinite recursive call beckon. … -
Proxying objects in Python
A lazy object proxy is an object that wraps a callable but defers the call until the object is actually required, and caches the result of said call. These kinds of objects are useful in resolving various dependency issues, few examples: Objects that need to held circular references at each other, but at different stages. To instantiate object Foo you need an instance of Bar. Instance of Bar needs an instance of Foo in some of it methods (but not at construction). Circular imports sound familiar? Performance sensitive code. You don't know ahead of time what you're going to use but you don't want to pay for allocating all the resources at the start as you usually need just few of them. There are other examples, I've just made up a couple for context. If you've used Django you may be familiar with SimpleLazyObject. For simple use-cases it's fine, and if you're already using Django the choice is obvious. Unfortunately it's missing many magic methods, most glaring omissions: __iter__, __getslice__, __call__ etc. It's not too bad, you can just subclass and add them yourself. But what if you need to have __getattr__? The horrors of the infinite recursive call beckon. … -
Django Forms
This is another example of Django's reusability. We saw how to create your own form in HTML and render it and get data from it using GET or POST methods. Again, Django does this for you. While it certainly is useful knowing how to do this on a basic level, using Django's Forms API can give you more powerful forms with richer features.Like models.py, create a file called forms.py in the app where the form is required. Let's create a simple contact form. In forms.py:forms.pyfrom django import formsclass SimpleUploadForm (forms.Form): name = forms.CharField (label = "Enter name") email = forms.EmailField (label = "Enter email ID", required = False) dob = forms.DateTimeField (label = "Enter date of birth")As you can see, just like a model, we created a simple form. Now let's render it from a view. views.pyfrom django.shortcuts import renderfrom forms import SimpleContactFormdef simple_contact_form (request): form = SimpleContactForm () return render (request, "simple_contact_form.html", {"form":form})Here, we import the SimpleContactForm class from forms.py and initialize its instance in the view. Then we pass that instance as a context to the webpage we're rendering. The view will become clearer when you see the template.simple_contact_form.html<html> <head><title>Simple Contact Form</title></head> <body> <form action = "" … -
Macbook pro black screen and restart problem
This morning I took my macbook pro (a very nice late 2014 retina 15" one) out of my backpack, opened it and plugged in the external monitor. But it stayed black. The macbook's own screen also stayed black. Ouch? It didn't seem to wake up... Some standard things I checked/tried: The battery couldn't be empty yet. The apple logo on the back of the screen was illuminated, right? Of course I had already attached it to the power cord. Which showed its LED, so power wasn't the problem. Screen brightness. Perhaps I dialed it down to zero by accident? No. Close/open again. Take out external display. Etc. Nope. Ok, time to press the power button. No reaction that I could see/hear. Press it 10 seconds. No. Problem with such a new macbook is that it doesn't have a harddisk. The noises a harddisk makes tend to provide pretty good feedback on what's happening normally :-) I just couldn't get the macbook to reset (or shut down)! If the power button doesn't work... Googling turned up two additional tricks: Resetting the "SMC", the system management controller. One of the things it does is monitor the power button... Press shift-option-control-power and release … -
Integrating front-end tools with your Django project
Front-end tools like Grunt and Gulp are becoming very widespread, and there’s good reason for it. The front-end code is no longer static, CSS pre-processors are the norm, and JavaScript modules such as Require, Browserify or even coffeescript are also becoming more common as well. On top of that, when you’re deploying to production, you want to minify everything but when you’re in development mode, you want sourcemaps for JS and CSS among other things. At Lincoln Loop, we use Gulp as our task runner to do the following things: Compile Sass into CSS, including autoprefixer support Compile JavaScript with Browserify Add sourcemaps for our compiled JavaScript and CSS Minify images with imagemin Reload the browser automatically on JavaScript (and/or template) changes Refresh the CSS without reloading the browser on CSS changes Trigger system notifications when Sass or JavaScript has errors Minify JavaScript and CSS for production deploy and finally: Generate a build folder where all the generated files are stored We won’t go into details about our Gulp setup on this post, there’s plenty of information out there (we wrote about Grunt before). If you’re curious about the code thou, here’s a gist of a gulpfile-in-one that includes most … -
Example Ember.js + Django + Django Rest Framework single-page application
Ember.js is one of JavaScript frameworks for creating interactive single page web applications. Pages may change but the browser doesn't reload the page. This framework has some similarities with Django and can be good pick to start with such frontend applications for Django developers with some JavaScript knowledge. In this article I'll show you an example Django + Django Rest Framework + Ember.js application. Classical posts and categories done in Ember and in Django for comparison. -
HTTP headers
Many times you many need the IP address of the computer that's accessing your webapp. You may want it for a survey, or cataloging that user to offer better services and what not. Today we'll see not only how to get the IP address, but a host of other client side information that can be used to fine tune your app.Let's take the IP address for example. I once needed it to see from where the app was being accessed from the most. I wrote a tracker that would piggyback on the client's signal and work backwards all the way to the source and get me the IP address. But little did I know that Django already does that for me. The IP address and host name (ISP) is encoded in the request parameter. Let's see how to view them.To do this we'll create a simple view. In HTML, we'll create a list that contains header name and value, and then populate it through Django.headers.html<html> <head><title>Django HTTP headers</title></head> <body> <ul> {% for header in headers %} … -
App specific URLs
As you may know, Django boasts reusability of apps. This means you can just copy one app from one project, plug it into another and it would still work the same way. Neat, huh? Well, admittedly, till now we've only focused on getting out projects to run. But now that we know the basics of creating a working Django project, it's time to delve deeper and take advantage of Django's rich features.Let's start with URLs. Till now, we just went on adding URLs to the main urls.py as we developed the project. But when the number of URLs starts going into the triple digits, the urls.py file can become massive and difficult to keep track of. So let's see how to create a urls.py file in each app and direct the main file to this new one.In the main urls.py file, add a pattern that will point to the app:url (r'^myapp/', include('myproject.myapp.urls')),This tells Django that whenever someone access the /myapp/ URL they should be directed to the urls.py file in that app. From here on in, all the views rendered in this app will have URLs like /myapp/foo/bar. This makes them easier to manage. There's also another advantage: you no longer need unique …