Django: how to create PDF, MS Word and Excel documents from templates. CTO with a CEO flavour. If you’re building a Django system that implies serving some kind of documents like reports or bills, chances are you want to provide docs in various formats from PDF to MS Word to HTML.
But how to implement this without resorting to numerous templates and packages for each document type?
Testing in Django (part 1) - Best practices and examples. Testing is vital.
Without properly testing your code, you will never know if the code works as it should, now or in the future when the codebase changes. Countless hours can be lost fixing problems caused by changes to the codebase. What’s worse, you may not even know that there are problems at all until your end users complain about it, which is obviously not how you want to find out about code breaks. Having tests in place will help ensure that if a specific function breaks you will know about it. Tests also make debugging breaks in code much easier, which saves time and money. I’ve literally lost gigs in the past from not properly testing new features against the old codebase.
Testing helps you structure good code, find bugs, and write documentation. Simple production-time debugging in Django – and better error handling. We all know how amazingly exhaustive Django debugging can be, when you enable the Debug = True option in your settings file.
It gives you a full traceback, complete with the str-ed versions of local variables. However, this post deals with the production-time scenario, when you might encounter an un-anticipated error in your code. Such errors can arise out of various reasons, such as- Django Performance: 4 Simple Things. By Frank Wiles on May 6, 2015 Optimizing for performance often comes with a bunch of headaches and hard problems, but it doesn’t always have to be that way.
Below are four simple things you can do to quickly and easily improve the performance of your sites. They’re so simple you should make them part of your standard setup. Persistent database connections. Opbeat. Tutorial: Celery with Periodic Tasks on Django : django.
Twisted. Twisted is an event-driven networking engine written in Python and licensed under the open source MIT license. Twisted runs on Python 2 and an ever growing subset also works with Python 3. Twisted makes it easy to implement custom network applications. Here's a TCP server that echoes back everything that's written to it: from twisted.internet import protocol, reactor, endpoints class Echo(protocol.Protocol): def dataReceived(self, data): self.transport.write(data) class EchoFactory(protocol.Factory): def buildProtocol(self, addr): return Echo() endpoints.serverFromString(reactor, "tcp:1234").listen(EchoFactory()) reactor.run() Learn more about writing servers, writing clients and the core networking libraries , including support for SSL, UDP, scheduled events, unit testing infrastructure, and much more.
Twisted includes an event-driven web server. Learn more about web application development, templates and Twisted's HTTP client. SwampDragon - build real-time apps with Django. VirtualEnvForNewerDjango - PythonAnywhere. A virtualenv is a way to have your own private Python environment that has different versions of packages to the system default.
You can have many virtualenvs, each with its own versions of installed packages. On PythonAnywhere, this is a great way to use newer (or older) versions of software than the ones we have installed. Squ1b3r/Djaneiro. Obey the Testing Goat! Someone recently wrote to me asking about decorators, and saying they found them a bit confusing.
Here's a post based on the email I replied to them with. The best way to understand decorators is to build a couple of them, so here are two examples for you to try out. The first is in the Django world, the second is actually a simpler, pure-python one. Challenge: build a decorator in a simple Django app We've built a very basic todo lists app using Django.
Getting Started with Django Logging in 5 Minutes. Getting Started with Django Logging in 5 Minutes posted by Ian on April 16, 2013 Setting up Django logging can sometimes be a little complex, so here are the no-nonsense steps required to make a new Django 1.5 instance log to a file without hassles.
We’re going to look at each of the 4 components of Django logging: High Performance Django The Book. The step-by-step tutorial I wish I had when learning Ajax in Django (with JQuery) — Part one of three. This tutorial demonstrates implementing Ajax in Django, using JQuery, for two specific tasks: A search box that executes on each key press.A like button that says "yes" if it’s liked, and "no" if it’s not.
Take a look at a mockup of the website we’re going to be creating, which is written in Knockout. (Here it is again as a JSFiddle.) In addition, we’ll add in some basic protection against rapid-fire requests, by preventing the search form from submitting until at least two characters are provided, and by ignoring clicks of the same like-button if it is pressed again within a half-second. First we’ll create the website without Ajax, and then we’ll integrate the Ajax calls. Get_context_data alternative. Tags: django There’s a super nice super elegant productivity trick for Django class based views.
Something that is not very well know, as I discovered at last week’s djangocon. So... time to share it! The problem? Regular Expressions. This quick start gets you up to speed quickly with regular expressions.
Obviously, this brief introduction cannot explain everything there is to know about regular expressions. For detailed information, consult the regular expressions tutorial. Each topic in the quick start corresponds with a topic in the tutorial, so you can easily go back and forth between the two. Many applications and programming languages have their own implementation of regular expressions, often with slight and sometimes with significant differences from other implementations.
When two applications use a different implementation of regular expressions, we say that they use different "regular expression flavors". Text Patterns and Matches A regular expression, or regex for short, is a pattern describing a certain amount of text. Cheat Sheet. The django tutorials are quite good.
The goal of this cheat sheet is to create a quick start guide so that after reading the tuts over once or twice you have a more handy reference. Things in this guide are done the 'right' way with generic views and templates right off the bat. Please please add to this page. (It would be great if some of the stuff from this page could later be rolled in to the startproject command and handled automatically - SimonWillison) Tango with Django.