Django community: Community blog posts RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Django transactional
When hacking django transactional projects i usually en up write a lot of views that are basically the same: present a ModelForm -> accept form data as POST -> create new entry and then another one that does basically the same with the only difference that it'll edit an old entry rather than creating a new one, if you've found your self doing this over and over again you might find this post useful.Today i published a first usable beta of a solution to this issue under BSD license: Django-transactional. It'll take all that off the table for you and create all needed stuff, i even published it on pypi for installing convenience. It still needs some love on the documentation front, but it's fairly easy to use, you only need a couple of things:Install Django-transactional:$ pip install Django-transactionalAdd urls:Add dtrans.urls to your projects urls.py file:url(r'^', include('dtrans.urls')),This will match /APP/MODEL/add/ and /APP/MODEL/add/OBJ_IDCreate your templates:Templates must be named AppName_ModelName.html, so if you want to use Foo model of Bar app create a template named bar_foo.html that uses obj_form form on it:{% csrf_token %}{{ obj_form.as_p }}With this you are ready to go. Django-transactional will create a basic ModelForm for your form and you will … -
Virtualenv med Python2.7 på FS-Data
(This blogpost is just available in swedish, since it involves a swedish webhost) Jag har tidigare skrivit hur man får igång Django på FS-Data. För ett par månader sen så uppdaterade de sin Pythontolk till 2.7, vilket gjorde livet bra mycket roligare. Något som gör livet än mer roligare är virtualenv. Virtualenv är en virtuell miljö som du installerar dina pythonpaket i så slipper du paket som kolliderar eller, vara beroende av att paket installeras system wide. Portabiliteten blir superb genom att man bara specar ens pythonpaket i en fil (requirements.txt) som man sedan använder när man deployar ut sin kod. Virtualenv är de facto-standard i Pythonvärlden och något varje Pythonutvecklare borde lära sig. Här följer en kort guide för hur du får igång virtualenv på FS-Data. SSH:a in på ditt FS-Datakonto, du kan göra livet lättare genom att logga in utan lösenord, vilket gör automatiska deployments bra mycket smidigare. ssh konto@konto.fsdata.se Skapa en mapp där de pythonpaket du behöver installera på ditt konto ska bo. mkdir site-packages Börja med att skapa .bash_profile och ändra i lite sökvägar: echo 'export PYTHONPATH=“$HOME/site-packages/" export PATH="$PATH:$HOME/site-packages/"' > .bash_profile Installera pip och virtualenv genom easy_install easy_install --install-dir=$HOME/site-packages pip; easy_install --install-dir=$HOME/site-packages virtualenv Nu har du … -
Drafts, reviews and in-future posts with Django-dress-blog
Allow authors/reviewers see content in draft mode, review mode, or waiting to hit the publication date. The draft mode and in-future posts are must-have features in any blog application. And when the blog is the result of a team the review mode comes very handy too. Since recent changes Django-dress-blog supports the **review mode** too, so that an author can set a story in **review** to get feedback from other authors before releasing the content to the public. Along with the review mode authors can also preview unpublished content in the blog, a new menu item allows switching on and off the visualization of unpublished content. This features are already available in the live demo. Here I introduce them in short and refer to the demo to see them in action. ##### Writing drafts A draft preview The simplest writing flow that works for single authored blogs consist of: 1. Writing the draft and previewing it until it looks wonderful. 2. Then set the publication time, make the status "Public", and submit. To start writing the draft you don't do anything special, just click on "Add" or "Add story", in the administrative interface of your blog. Posts are created with … -
Running two services at once on Dotcloud
If you’re a regular of my old personal blog you know that I have tested most of the more well known Django hosting services. The reason I chose Dotcloud for this project was that it involved both Django and NodeJS, and to make it more of a mess it it as web that both is an online and an offline web (yep, HTML5 appcache). For the offline part we are actually using some CommonJS modules straight in the browser. And to protect these files and not get the application server to serve those files we needed to be able to customize the Nginx configuration. So to make all these pieces fit nicely on just one host the choice was pretty easy, Dotcloud. So how do we deploy a two (or more) service thingie in Dotcloud? It’s actually very easy. You just add one more service in your dotcloud.yml, like: www: type: python approot: cleverfoldername node: type: nodejs approot: cleverfoldername/node config: node_version: v0.6.x This will fire up two instances, one for the django service and one for the nodejs service. As you can see the root for the nodejs service is actually inside of the django service, this is because we … -
Drafts, reviews and in-future posts with Django-dress-blog
Allow authors/reviewers see content in draft mode, review mode, or waiting to hit the publication date. The draft mode and in-future posts are must-have features in any blog application. And when the blog is the result of a team the review mode comes very handy too. Since recent changes Django-dress-blog supports the **review mode** too, so that an author can set a story in **review** to get feedback from other authors before releasing the content to the public. Along with the review mode authors can also preview unpublished content in the blog, a new menu item allows switching on and off the visualization of unpublished content. This features are already available in the live demo. Here I introduce them in short and refer to the demo to see them in action. #### Writing drafts A draft preview The simplest writing flow that works for single authored blogs consist of: 1. Writing the draft and previewing it until it looks wonderful. 2. Then set the publication time, make the status "Public", and submit. To start writing the draft you don't do anything special, just click on "Add" or "Add story", in the administrative interface of your blog. Posts are created with … -
Notes on Serving Django Apps with uWSGI
Notes on serving Django apps with Nginx/uWSGI -
We need more PyCon US 2013 submissions!
The PyCon US 2013 call for papers (CFP) ends tomorrow, September 28th, 2012. We need more talk and tutorial submissions. Talks are 30 or 45 minute efforts in front of the PyCon audience and are recorded for posterity. Tutorials are three hours long and are given to attendees who have paid an additional fee in order to slurp in knowledge from the masters. On the 3 hour tutorial side of things, we especially need more Intro to Python level submission. That means getting beginners up to speed on basic Python techniques, so they can then exploit the other tutorials, conference, and sprints to their full advantage. Now onto some questions... 1. I would like to give a tutorial but it's so much work to put together 3 hours of quality content. The organizers of PyCon recognize that putting together a quality tutorial is an amazing amount of work. Which is why tutorial presenters are compensated for their effort. 2. What is the most likely length talk to be accepted? 30 minutes or 45 minutes? The vast majority of PyCon sessions are 30 minutes long, so 45 minute slots are rare and valuable commodities. So if your talk needs to be … -
We need more PyCon US 2013 submissions!
The PyCon US 2013 call for papers (CFP) ends tomorrow, September 28th, 2012. We need more talk and tutorial submissions. Talks are 30 or 45 minute efforts in front of the PyCon audience and are recorded for posterity. Tutorials are three hours long and are given to attendees who have paid an additional fee in order to slurp in knowledge from the masters. On the 3 hour tutorial side of things, we especially need more Intro to Python level submission. That means getting beginners up to speed on basic Python techniques, so they can then exploit the other tutorials, conference, and sprints to their full advantage. Now onto some questions... 1. I would like to give a tutorial but it's so much work to put together 3 hours of quality content. The organizers of PyCon recognize that putting together a quality tutorial is an amazing amount of work. Which is why tutorial presenters are compensated for their effort. 2. What is the most likely length talk to be accepted? 30 minutes or 45 minutes? The vast majority of PyCon sessions are 30 minutes long, so 45 minute slots are rare and valuable commodities. So if your talk needs to be … -
Contributing to Django Documentation, Part 2: Submitting A Patch
Contributing to Django Documentation, Part 2: Submitting A Patch -
QuerySets, Q Objects, datetime, and Far Too Much Context
QuerySets, Q Objects, datetime, and Far Too Much Context -
Going Mobile with Django and jQuery
Going Mobile with Django and jQuery -
DjangoCon 2012 Recap
DjangoCon 2012 Recap -
Contributing to Django Documentation, Part 1: Generating and Editing Documentation Locally
Contributing to Django Documentation, Part 1: Generating and Editing Documentation Locally -
Initial Data Using South Migrations
Usually when starting a new project with commonly used apps, you will need some default data for the database, for example, default categories. Django provides fixtures for that. A fixture is a collection of data that Django knows how to import into a database. They say: If you create a fixture named initial_data.[xml/yaml/json], that fixture will be loaded every time you run syncdb. There is one problem with this approach. It is very likely that you will need to run syncdb in the future when adding new apps (without south migrations). In such cases the modified data will be overwritten with the initial data from fixtures. But there is a solution for that problem. You need to name your fixtures differently and then import them by south migrations. If you don't use south, you should start doing that, because it is a very handy way to modify database schema and data automatically. :) So this is how you can prepare south migration with the default fixture: 1. Create a fixture from existing models. python manage.py dumpdata --format=json --indent=4 myapp.Category > /path/to/myapp/fixtures/myapp_categories.json 2. Create data migration python manage.py datamigration myapp load_default_data 3. Edit data migration class Migration(DataMigration): def forwards(self, orm): from … -
We need more PyCon US 2013 submissions!
The PyCon US 2013 call for papers (CFP) ends tomorrow, September 28th, 2012. We need more talk and tutorial submissions. Talks are 30 or 45 minute efforts in front of the PyCon audience and are recorded for posterity. Tutorials are three hours long and are given to attendees who have paid an additional fee in order to slurp in knowledge from the masters. On the 3 hour tutorial side of things, we especially need more Intro to Python level efforts. That means getting beginners up to speed on basic Python techniques, so they can then exploit the other tutorials, conference, and sprints to their full advantage. Now onto some questions... 1. I would like to give a tutorial but it's so much work to put together 3 hours of quality content. The organizers of PyCon recognize that putting together a quality tutorial is an amazing amount of work. Which is why tutorial presenters are compensated for their effort. 2. What is the most likely length talk to be accepted? 30 minutes or 45 minutes? The vast majority of PyCon sessions are 30 minutes long, so 45 minute slots are rare and valuable commodities. So if your talk needs to be … -
Project Mwana featured in the BBC
Caktus has had the opportunity to work on the infrastructure of RapidSMS, an application framework that allows data collection and logistics coordination using mobile phone text messages for communication. The BBC World News recently posted an article, "RapidSMS: Saving a life in 160 characters" detailing the effects of RapidSMS technology is having on HIV/AIDS treatment in the developing world. The article focuses on work being done to combat the HIV/AIDS epidemic in Malawi where there is one of the highest rates of infection in the world. The statistics are sobering. More than 11% of Malawi's adults are living with HIV and around 120,000 children are thought to have the disease. [. . .] Annually, the United Nations estimates that 25% of new infections in the country are caused by mother-to-child transmission of the virus. That means it's absolutely critical that infants in Malawi get tested for HIV as soon as possible in the weeks following birth, and if they test positive, that treatment begins immediately. One of the main programs that has dramatically transformed the landscape of reporting test results is Project Mwana. Mwana, which means “baby” or “child” in Swahili, focuses on reducing the mother-to-child infection rate by using … -
Getting an IP Address in Django behind an Nginx Proxy
How to get the client IP address in Django when running Django behind an Nginx reverse proxy server. -
Django project file structure
As I promised in Automated deployment with Ubuntu, Fabric and Django I will use this post to explain the file structure that I use for my Django projects and what I benefit from it. So here is my project directory tree. The structure ~/workspace/<project_name>/ |-- bin |-- include |-- lib |-- local |-- src |-- .git |-- .gitignore |-- required_packages.txt |-- media |-- static |-- <project_name> | |-- <project_name> | | |-- __init__.py | | |-- settings | | | |-- __init__.py | | | |-- <environment_type>.py | | | |-- local.py | | |-- templates | | |-- urls.py | | |-- views.py | |-- manage.py | |-- wsgi.py |-- <project_name>.development.nginx.local.conf |-- <project_name>.< environment_type>.nginx.uwsgi.conf |-- <project_name>.< environment_type>.uwsgi.conf Explanation At the top I have a directory named as the project and virtual environment inside of it. The benefit from it is complete isolation of the project from the surrounding projects and python packages installed at OS level and ability to install packages without administrator permissions. It also provides an easy way to transfer the project from one system to another using a requirements file. The src folder is where I keep everything that is going to enter the version control … -
SSL behind an Nginx Reverse Proxy in Django 1.4
I recently upgraded one of my e-commerce websites to Django 1.4 and was very pleased to find the new SECURE_PROXY_SSL_HEADER setting. -
Demo live sites for 3 django apps
In the documentation of django-comments-xtd, django-inline-media and django-dress-blog I explain how to install the demo site of each application. However, sometimes it's useful to see the demo up and running before putting our hands on the code. With that intention I have set up demo sites for the aforementioned django apps. In order to see how they are integrated with the admin interface the three demos allow admin access too. You can see the already existing model instances, modify them and add new instances. Just keep in mind that the database is initialized every 30 minutes. The user and password are **admin**, **admin**. ##### Demos for django-comments-xtd Django-comments-xtd comes with two demos. The first live demo consist of just an app with one model, Article, whose instances accept comments. Simplicity helps to understand the basics. The second live demo allows site visitors to add comments to instances of various models. The intention is to show that it's possible to list comments sent to instances of different models presenting them as a feed. Two templatetags, `get_last_xtdcomment` and `render_last_xtdcomments`, offers such functionality, that reveals to be very useful in sites where traffic comes from user comments. The two demos for django-comments-xtd are: … -
Demo live sites for 3 django apps
In the documentation of django-comments-xtd, django-inline-media and django-dress-blog I explain how to install the demo site of each application. However, sometimes it's useful to see the demo up and running before putting our hands on the code. With that intention I have set up demo sites for the aforementioned django apps. In order to see how they are integrated with the admin interface the three demos allow admin access too. You can see the already existing model instances, modify them and add new instances. Just keep in mind that the database is initialized every 30 minutes. The user and password are **admin**, **admin**. ##### Demos for django-comments-xtd Django-comments-xtd comes with two demos. The first live demo consist of just an app with one model, Article, whose instances accept comments. Simplicity helps to understand the basics. The second live demo allows site visitors to add comments to instances of various models. The intention is to show that it's possible to list comments sent to instances of different models presenting them as a feed. Two templatetags, `get_last_xtdcomment` and `render_last_xtdcomments`, offers such functionality, that reveals to be very useful in sites where traffic comes from user comments. The two demos for django-comments-xtd are: … -
django CMS 2.3.3 released
-
Django cache templatetag with dynamic backend parameter
I've found a nice project django-adv-cache-tag. From the project website: With django-adv-cache-tag you can : add a version number (int, string, date or whatever, it will be stringified) to you templatetag : the version will be compared to the cached one, and the exact same cache key will be used for the new cached template, avoiding keeping old unused keys in your cache, allowing you to -
Pyramid, 2style4you and python - Wichert Akkerman
http://2style4you.com took up most of his time the last years: it provides automatic fashion recommendations for women. They use lots of technologies, for instance redmine, jenkins, transifex, bitbucket (git), zabbix. They had a lot of fashion portals that needed building. What did they need for them? There wasn't a lot of standard functionality that they needed, like form generation for database models. So there was a lot in the big web frameworks at the time (django, plone, zope) that they did not need. What they did need was customizability, all sites do things differently. And it needed to be fast. And internationalization was needed (he later showed a Taiwanese site, for instance). And he needed it to be in Python because Wichert knows that well. He started out with pylons, a mini framework. But after a while it wasn't really maintained anymore. Then they migrated to repoze.bfg (by Chris McDonough), another mini framework. They took about two months to migrate the whole thing (with the help of the repoze.bfg author). The fun thing is that repoze.bfg got merged into the pylons project later on; it is now called pyramid. They make a core website that provides the main functionality. Then … -
toastdriven/django-tastypie
toastdriven/django-tastypie. Hatte ich glaube ich schon mal, macht aber nix, sieht immer noch interessant aus – eine Alternative zu django-piston mit einer deutlich weitergehenden Funktionalität (zum Beispiel recht ausführliche Optionen für Authentifizierung und Authorisierung). Was es macht? REST Interfaces für Django Modelle inklusive deren Relationen. In den verschiedensten Formaten (XML, JSON, YAML).