Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
- 
        How and why to use pyflakes to write better PythonHere is another of the screencasts I created for "Getting started with Python" series. Liked them? Let me know what else would you like me to create screencasts about?
- 
        Screencast: Django Tutorial Part 1Django Screencast Tutorial 1 from Shabda Raaj on Vimeo. I am creating screencasts for Django tutorial and other Django videos. Here is part 1. Liked this? Leave me a comment or email me and tell me what would you like me to create screencasts for. (Watch the screencast in full screen mode.)
- 
        How to use pep8.py to write better Django codeHere is another or screencast I created for my "Getting Started with Django" series. Like this? Email us on what would you like to see. (Watch in fullscreen.)
- 
        Deploying Django apps on HerokuRead this first: http://devcenter.heroku.com/articles/django. This is a great article by the Heroku. I am just filling in some more details and making this step-by-step. Get your Django project code. Create a virtualenv with a no-site-packages command virtualenv vent --no-site-packages Install Django, psycopg2 (postgres connector), gunicorn and any other required Django libraries. Confirm that you have all the required libraries and you can run your code locally using manage.py runserver. Create a requirement.txt by using pip freeze > requirements.txt Make sure you have a requirements.txt at the root of your repo. Heroku uses this to identify that the app is a Python app. Create a Procfile. Put this entry: web: python mysite/manage.py run_gunicorn -b "0.0.0.0:$PORT" -w 3shabda This is what your directory structure will look like [root-of-heroku-folder] requirements.txt Procfile [Django-project-folder] __init__.py manage.py settings.py [app1] [app2] (If you aren't tracking your files with git yet.) Track your files with git. git init git add . git commit -am "First commit" Make sure you have the heroku toolbelt installed. If not go to http://toolbelt.herokuapp.com/ and install. 11.You should have these commands available now: heroku foreman Authenticate to heroku with heroku auth:login Run this command. heroku create --stack cedar This will create a new …
- 
        Dynamically attaching SITE_ID to Django CachingIt would be useful and convenient, if you have an automatic way to add the SITE_ID, especially, when you have multiple sites running on the same deployment. Django provides a cache prefix function KEY_FUNCTION in settings which can be used to achieve this. Just follow the following steps, and your cache, automatically prepends SITE_ID to the cache key, making it unique across multiple sites. Put the following into the settings file. CACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.db.DatabaseCache', 'LOCATION': 'cache_table', KEY_FUNCTION = ‘projectname.appname.modulename.functionname’, } } Write a function to get current site id, say, get_current_site(), which returns current SITE_ID. Add a function like below, as functionname at the same path as specified in KEY_FUNCTION. from django.utils.encoding import smart_str def prefix_site_id(key, key_prefix, version): site_id = get_current_site() return ':'.join([str(site_id), str(version), smart_str(key)]) That’s it. You have successfully added an automatic, dynamic, function based cache prefix for django.
- 
        Deploy Django App in 5 Easy StepsSo you just bought a new VPS, have installed Ubuntu and want to deploy your django app, GREAT!! We shall get your app, up and running in 5 easy steps, using best(arguably) of tools available. The post is targeted to audience who are new to deployment arena, but assumes you are comfortable with developing basic django apps. We shall be using gunicorn as our server and nginx nginx as our reverse proxy and static hanlder. Here we go: 1. Login and OS Updation: $ ssh root@{your_ip} # apt-get update # apt-get upgrade # apt-get dist-upgrade # dpkg-reconfigure tzdata #choose your time zone 2. Setup Users and Permissions: # useradd agiliq # mkdir /home/agiliq # chown agiliq:agiliq /home/agiliq # passwd agiliq #choose a password # chsh agiliq -s /bin/bash #choose a shell # visudo #lets give sudo access to the user agiliq root ALL=(ALL) ALL agiliq ALL=(ALL) ALL # su agiliq # switch from root to agiliq 3. Install necessary stuff and create a dev environment: $ sudo apt-get install python-pip git mysql-client mysql-server $ python-mysqldb nginx emacs(you might choose vim or stick to default vi/nano) $ pip install virtualenv #please refer to documentation of virtualenv $ virtualenv projhq # creates …
- 
        Deploying Django apps on HerokuDeploying Django apps on Heroku: Read this first: http://devcenter.heroku.com/articles/django. This is a great article by the Heroku. I am just filling in some more details and making this step-by-step. Get your Django project code. Create a virtualenv with a no-site-packages command :: virtualenv vent --no-site-packages Install Django, psycopg2 (postgres connector), gunicorn and any other required Django libraries. Confirm that you have all the required libraries and you can run your code locally using manage.py runserver. Create a requirement.txt by using :: pip freeze > requirements.txt Make sure you have a requirements.txt at the root of your repo. Heroku uses this to identify that the app is a Python app. Create a Procfile. Put this entry: :: web: python mysite/manage.py run_gunicorn -b "0.0.0.0:$PORT" -w 3shabda This is what your directory structure will look like :: [root-of-heroku-folder] requirements.txt Procfile [Django-project-folder] __init__.py manage.py settings.py [app1] [app2] (If you aren't tracking your files with git yet.) Track your files with git. :: git init git add . git commit -am "First commit" Make sure you have the heroku toolbelt installed. If not go to http://toolbelt.herokuapp.com/ and install. 11.You should have these commands available now: :: heroku foreman Authenticate to heroku with :: heroku auth:login …
- 
        Progress Report March 11th, 2013After the break Sorry for the lack of updates, but last week was spring break at the College of Charleston. I had initially planned to complete a few bug fixes for Django, but this did not occur. Instead of working on Django, I spent the break visiting old friends, and applying for internships. I already have another interview on Wednesday, which hopefully go better than my last one. On the Django front, I did have one more documentation change accepted, so not all is lost. As for Team Django a couple of other contributions have been accepted, and some are awaiting review from the core developers. In the wake of the release of Django 1.5 and multiple Django sprint events, many of our targeted issues have been or are being addressed. Having just recently combed back through the tickets that are not feature requests many tend to deal with database interactions or other implementations of Python (Jython, PyPy, and IronPython). Having little to no real world experience with databases and none at all with the other implementations of Python, I'm a little bit hesitant to claim any of these tickets. Nevertheless, the Team is scouring through the tickets, and I …
- 
        Beginner's Guide to PyCon 2013 Part IIIThis is Part III in a series of blog posts about PyCon US 2013. The goal is to provide a handy reference guide for first time attendees of the world's largest Python conference. Part I was mostly about tutorials, Part II was mostly about the first day of talks, this third post in the series will be about the second day of talks. Early Saturday Morning The PyCon 5K Charity Fun Run begins at 7 AM. Registration for this event is seperate from PyCon, and all proceeds go to the John Hunter Memorial Fund and the American Cancer Society. Saturday Morning After breakfast ends at 8:30 am, don't miss 30 minutes of lightning talks! Then get ready as noted Python experts and proven speakers Jessica McKellar and Raymond Hettiger deliver keynotes to remember. They've changed communities and lives with the speeches given around the world. 10:50 AM talks Getting started with automated testing (Carl Meyer) - This talk will get you moving into good test automation practices, and is presented by one of the maintainers of Django, pip, and virtualenv. 5 powerful pyramid features (Carlos de la Guardia) - Pyramid is a minimalist, modular web framework that encourages excellent coding …
- 
        Beginner's Guide to PyCon 2013 Part IIIThis is Part III in a series of blog posts about PyCon US 2013. The goal is to provide a handy reference guide for first time attendees of the world's largest Python conference. Part I was mostly about tutorials, Part II was mostly about the first day of talks, this third post in the series will be about the second day of talks. Early Saturday Morning The PyCon 5K Charity Fun Run begins at 7 AM. Registration for this event is seperate from PyCon, and all proceeds go to the John Hunter Memorial Fund and the American Cancer Society. Saturday Morning After breakfast ends at 8:30 am, don't miss 30 minutes of lightning talks! Then get ready as noted Python experts and proven speakers Jessica McKellar and Raymond Hettiger deliver keynotes to remember. They've changed communities and lives with the speeches given around the world. 10:50 AM talks Getting started with automated testing (Carl Meyer) - This talk will get you moving into good test automation practices, and is presented by one of the maintainers of Django, pip, and virtualenv. 5 powerful pyramid features (Carlos de la Guardia) - Pyramid is a minimalist, modular web framework that encourages excellent coding …
- 
        django-fancy-cache with or without statsIf you use django-fancy-cache you can either run with stats or without. With stats, you can get a number of how many times a cache key "hits" and how many times it "misses". Keeping stats incurs a small performance slowdown. But how much? I created a simple page that either keeps stats or ignores it. I ran the benchmark over Nginx and Gunicorn with 4 workers. The cache server is a memcached running on the same host (my OSX 10.7 laptop). With stats: Average: 768.6 requests/second Median: 773.5 requests/second Standard deviation: 14.0 Without stats: Average: 808.4 requests/second Median: 816.4 requests/second Standard deviation: 30.0 That means, roughly that running with stats incurs a 6% slower performance. The stats is completely useless to your users. The stats tool is purely for your own curiousity and something you can switch on and off easily. Note: This benchmark assumes that the memcached server is running on the same host as the Nginx and the Gunicorn server. If there was more network in between, obviously all the .incr() commands would cause more performance slowdown.
- 
        Django Extensions 1.1.1Another bugfix release of Django-Extensions hits the deck. ChangeLog: FIX: pipchecker, fix typos FIX: pipchecker, improve message when installed version is newer then on pypi FIX: pipchecker, use urllib2 instead of requests FIX: sqldiff, fix for bigserial support
- 
        ArangoDB Driver for Python: added support of Python 3.3 and ArangoDB 1.2At least added support of Python 3.3 to the ArangoDB Python driver v 0.1.6 (github). Move forward with pip install arango. By default in Python 3.3 pycurl client will not work, so it's better to specify client by hands using: Also, added support of ArangoDB 1.2.
- 
        PyCon Tutorial: Wiring Up Django PackagesYou just finished the Django tutorial. What now? You learn how to Wire Up Django Packages! This is a 3+ hour PyCon tutorial on March 14th at 1:20pm, in Santa Clara California at PyCon US. In alphabetical order, the instructors: Audrey Roy Daniel Greenfeld (myself) Kenneth Love Tutorial Description Django is part of an ecosphere of over 20,000 packages, which can be leveraged to great effect. This tutorial will teach the evaluation, use, and extension of third party Python and Django applications in your projects. This tutorial will be a lecture with a lot of detailed and annotated code examples. This tutorial does much more than instruct on how to wire in third party packages, it also instructs on Django/Python best practices such as PEP-8, loose coupling, good database design, clarity of concept, and workable patterns. Material covered: Evaluating packages using Django Packages, PyPI, Read the Docs, and other sources. Must-include packages for every project Class-based Views Forms Models Caching Comments Templates Admin Format This will be a lecture with detailed and annotated code examples. Attendees will have a chance per section to ask questions and submit alternative packages of their own. Prerequisites Practical or professional experience with Django is …
- 
        PyCon Tutorial: Wiring Up Django PackagesYou just finished the Django tutorial. What now? You learn how to Wire Up Django Packages! This is a 3+ hour PyCon tutorial on March 14th at 1:20pm, in Santa Clara California at PyCon US. In alphabetical order, the instructors: Audrey Roy Daniel Greenfeld (myself) Kenneth Love Tutorial Description Django is part of an ecosphere of over 20,000 packages, which can be leveraged to great effect. This tutorial will teach the evaluation, use, and extension of third party Python and Django applications in your projects. This tutorial will be a lecture with a lot of detailed and annotated code examples. This tutorial does much more than instruct on how to wire in third party packages, it also instructs on Django/Python best practices such as PEP-8, loose coupling, good database design, clarity of concept, and workable patterns. Material covered: Evaluating packages using Django Packages, PyPI, Read the Docs, and other sources. Must-include packages for every project Class-based Views Forms Models Caching Comments Templates Admin Format This will be a lecture with detailed and annotated code examples. Attendees will have a chance per section to ask questions and submit alternative packages of their own. Prerequisites Practical or professional experience with Django is …
- 
        Caktus is hiring a Web Project ManagerCaktus is currently hiring for a full time Web Project Manager to be a part of our awesome team. We’re a diverse team of smart, sharp developers and designers with a passion for creating customizable, content rich sites and web applications using Django. As one of the project managers at Caktus, you’ll have the opportunity to develop your professional skills and also get the chance to work with some very capable and nice people.
- 
        Caktus is hiring a Web Project ManagerCaktus is currently hiring for a full time Web Project Manager to be a part of our awesome team. We’re a diverse team of smart, sharp developers and designers with a passion for creating customizable, content rich sites and web applications using Django. As one of the project managers at Caktus, you’ll have the opportunity to develop your professional skills and also get the chance to work with some very capable and nice people. We are looking for someone who is meticulous when it comes to detail, is able to see the overarching goals of projects and has a special place in their heart for spreadsheets. Also it would not hurt if you had knowledge about Django and agile web development. Your job will consist of assisting with product deployments, managing client communications and assisting with creating estimates for incoming projects. If you think you might be a great fit or know someone who might be, check out the full job posting here .
- 
        Taking Some Pain out of Python LoggingEven the best of us hate logging in Python sometimes. And while a lot of its problems are actually just bad docs and terrible defaults in the past, there is some pain that can be avoided. One of the big problems with logging in general is that every class and function reek of NIH in the name of cross-platform. And to make it even more fun, there are several ways to do it: standard library, Twisted, Logbook… For example to get useful log rotation by day (whoever came up with rotating by size may be a good idea‽), you’d go for TimedRotatingFileHandler in stdlib, but in Twisted everything works slightly differently. All of this isn’t just annoying, it’s also unnecessary. Your UNIX-like operating system – which you presumably use to deploy your applications – offers formidable solutions to both logging and rotating. It’s out there for you to use. Since the 1980s. Nowadays when I deploy web applications I use StreamHandler as logger which sends all logs go to stderr. For paster (Pylons/Pyramid) it looks like this: [handler_stderr] class = StreamHandler args = (sys.stderr,) level = INFO formatter = your_formatter For Django, you go with: 'handlers': { 'stderr': { 'level': …
- 
        Testing and tracking down Warnings in DjangoWarnings are often suppressed through many layers of control mechanisms in Python and Django. However, you should really be aware of these and clean them up once in a while! In other cases, the Warnings reflect an inconsistent state, such as if you are mixing naive and timezone-aware variables. It can be a real pain to track down RuntimeWarning because it doesn’t leave a nice stack trace. The scenario could be that you have assigned a naive DateTime to a field, and the db layer is complaining at runtime. However, you can run python in a mode where Warning-types raise exceptions with full stack traces. Use the following syntax: python -W error:"":RuntimeWarning:django.db.models.fields:0 manage.py runserver ‘error’ means that python should raise an exception – this is what we want! ‘RuntimeWarning’ means to trigger when such is raised – you can also simply put ‘Warning’ to trigger for all Warning types. ‘django.db.models.fields’ means activate for this module (you need the full path). Notice that simply putting ‘django’ does *not* activate for all of django, you need to put the specific module or simply ‘”"‘ to enable for all of Python (which might render some interesting Warning goodies that you have never seen!). …
- 
        This site is now 100% inline CSS and no bytes are wastedThis personal blog site of mine uses django-fancy-cache and mincss. What that means is that I can cache the whole output of every blog post for weeks and when I do that I can first preprocess the HTML and convert every external CSS into one inline STYLE block which will only reference selectors that are actually used. To see it in action, right-click and select "View Page Source". You'll see something like this: /* Stats about using github.com/peterbe/mincss ------------------------------------------- Requests: 1 (now: 0) Before: 81Kb After: 11Kb After (minified): 11Kb Saving: 70Kb */ section{display:block}html{font-size:100%;-webkit-text-size-adjust:100%;-ms-tex... The reason the saving is so huge, in my case, is because I'm using Twitter Bootstrap CSS framework which is awesome but as any framework, it will inevitably contain a bunch of stuff that I don't use. Some stuff I don't use on any page at all. Some stuff is used only on some pages and some other stuff is used only on some other pages. What I gain by this, is faster page loads. What the browser does is that it, gets a URL, downloads all HTML, opens the HTML to look for referenced CSS (using the link tag) and downloads that too. Once all …
- 
        Creating modern web applications with Django and ember.js JavaScript frameworkemberjs is a new JavaScript framework for building interactive/responsive web applications. Compared to "classical" approach it removes the need to write code for AJAX requests fetching, modifying data or for example code responsible for DOM manipulation. Like in good framework we write only the code implementing our app functionality/idea. emberj.js is quite a young project so the amount of tutorials isn't high nor the documentation isn't of Django level - but still it's there and it's not that bad. At the moment Ember is close to reaching the 1.0 release and it's quite stable allowing real production application development. In the same category we can also find other similar frameworks like Backboje.js or Angular.js. Each has its strong and weak points. In this article I'll showcase basic ember features and ember application development process for a Django-Tastypie-Ember application. You need at least basic Django and django-tastypie (REST API-making application for your models). The whole application developed in this article can also be downloaded and launched on your localhost.
- 
        Django Extensions 1.1.0We just released version 1.1.0 of Django-Extensions. This version brings initial support for both Django 1.5 and Python 3.3 ! Thanks to fhahn and Mikolaj Romel for their help on this. ChangeLog: Python 3.3 support Django 1.5 support PACKAGING: Added license file to source distribution FEATURE: Add pipchecker command for reporting out-of-date requirements FEATURE: Allow to set uuidfield max_length FEATURE: dumpscript got hooks to override save and locate calls FEATURE: notes command now also support WARNING and NOTE annotations FEATURE: shell_plus command now support settings SHELL_PLUS variable in settings file which indicated with interactive python shell to use. DOCS: Fixed documentation which was messing up the table of content. FIX: Added empty migration to make south happy :) FIX: UUID never appears on admin form FIX: reset_db would set OWNER = None when executed without db user FIX: shell_plus disabled using pythonrc per default.
- 
        We are not using PayPalIn January Audrey Roy and I launched a book about Django called Two Scoops of Django: Best Practices for Django 1.5. We decided to not use PayPal. Here's why: Open Source Events Get Burned By PayPal PayPal has a long, sordid history of freezing the accounts of Python related conferences and events around the world. In fact, this article was born out of the fact DjangoCon Europe 2013 had its PayPal account frozen. In the past, DjangoCon Europe 2012, Plone Conferences 2008, 2011, and at least one PyCon Australia dealt with the same PayPal problem (DjangoCon 2013 was forewarned and took measures to protect itself). We also have unconfirmed reports of other Python and Django events also running into problems with PayPal freezing accounts. Going with just confirmed conferences having issues with PayPal, this is a combined total of assets in excess of over US$100,000 dollars. It's not just a Python issue either, it's an issue that strikes other open source languages and tools. It's at the point now where conference organizers don't trust PayPal and make a point telling each other to use alternative payment gateways. Fear, Shame, and PayPal The terrifying thing to consider is that I suspect …
- 
        We are not using PayPalIn January Audrey Roy and I launched a book about Django called Two Scoops of Django: Best Practices for Django 1.5. We decided to not use PayPal. Here's why: Open Source Events Get Burned By PayPal PayPal has a long, sordid history of freezing the accounts of Python related conferences and events around the world. In fact, this article was born out of the fact DjangoCon Europe 2013 had its PayPal account frozen. In the past, DjangoCon Europe 2012, Plone Conferences 2008, 2011, and at least one PyCon Australia dealt with the same PayPal problem (DjangoCon 2013 was forewarned and took measures to protect itself). We also have unconfirmed reports of other Python and Django events also running into problems with PayPal freezing accounts. Going with just confirmed conferences having issues with PayPal, this is a combined total of assets in excess of over US$100,000 dollars. It's not just a Python issue either, it's an issue that strikes other open source languages and tools. It's at the point now where conference organizers don't trust PayPal and make a point telling each other to use alternative payment gateways. Fear, Shame, and PayPal The terrifying thing to consider is that I suspect …
- 
        Welcome to the world django-fancy-cache!A Django cache_page on steroids Django ships with an awesome view decorator called cache_page which is awesome. But a bit basic too. What it does is that it stores the whole view response in memcache and the key to it is the URL it was called with including any query string. All you have to do is specify the length of the cache timeout and it just works. Now, it's got some shortcomings which django-fancy-cache upgrades. These "steroids" are: Ability to override the key prefix with a callable. Ability to remember every URL that was cached so you can do invalidation by a URL pattern. Ability to modify the response before it's stored in the cache. Ability to ignore certain query string parameters that don't actually affect the view but does yield a different cache key. Ability to serve from cache but always do one last modification to the response. Incrementing counter of every hit and miss to satisfy your statistical curiosity needs. The documentation is here: https://django-fancy-cache.readthedocs.org/ You can see it in a real world implementation by seeing how it's used on my blog here. You basically use it like this:: from fancy_cache import cache_page @cache_page(60 * 60) def …