Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Django 1.7 正式版的新功能介绍
Django开发者及爱好者们期待已久的 1.7 正式版前两天终于发布了,据Django官网的介绍,这一版本相对 […] -
从 Apache 2.2 升级到 2.4 需要更新哪些 Virtual Host 设置?
如果你和我们一样从Ubuntu 12.04升级到Ubuntu14.04, 那么你会发现Apache版本从2.2变成了2.4; 或者你只是将Apache 2.2升级为2.4. 那么你可能会发现Apache无法正常工作了. 你可以使用本篇中所提到的设置时Apache重新工作. 本篇中所提到的Virtual Host设置文件的更新是必须要做的, 否则Apache就无法工作. 本篇博文并不是一个完整的升级指导, 如果需要查看完整的升级指导, 请访问Apache官方升级指导 1. 备份 在升级之前请备份数据文件, 因为升级有可能会使你丢失数据. 2. Virtual Host设置更新 从apache 2.2升级到Apache 2.4: 对于Ubuntu和Debian, 在etc/apache2/sites-available目录中的文件必须以.conf结尾才能被读取 Virtual host设置中的Directory必须有Require all granted才行 <Directory /path/to/public/website/> Require all granted </Directory> 所以, 对于Ubuntu和Debian用户, 你需要修改Virtual host中的2处设置才能使Apache 2.4重新运作, 而其他Linux的用户则只需要做第二项的修改. a. 增加.conf扩展名 (针对Ubuntu和Debian用户) 我们可以使用mv命令为Virtual host文件添加cong扩展名: mv /etc/apache2/sites-available/example.com /etc/apache2/sites-available/example.com.conf 然后使用阿ensite命令重新增加virtual host, 不要忘了添加.conf后缀: a2ensite example.com.conf 对所有virtual host文件重复以上两步, 最后重新载入: sudo service apache2 reload b. 增加权限 (针对所有用户) 打开网站的virtual host文件, 例如/etc/apache2/sites-available/example.com.conf, 在VirtualHost下的Directory中添加Require all granted. 如果存在Require all denied, 则改为Require all granted: <VirtualHost *:80> ... <Directory /path/to/public/website/> Require all granted </Directory> ... </VirtualHost> 保存并对其他virtual host文件执行以上步骤, 最后重新载入: Ubuntu/Debian: sudo service apache2 reload CentOS: /etc/init.d/httpd reload Fedora: systemctl reload httpd.service 此时检查网站是否能正常运行. 3. 其他注意事项 升级过程中默认的virtual host文件可能会从/var/www变为var/www/html, 不要忘了重新静止它. 升级后如果有不兼容的模块的话, 这些模块也会组织apache正常运行, 此时Apache官方升级指导是检查的起点. -
Factory Boy Fun
I’ve recently been working on improving the test suite at YPlan. The biggest change is moving towards dynamic fixtures for our Django models using “Factory Boy”. This library is essentially a tool that lets you define simple helper functions to generate random, sensible model instances quickly; by using them in tests you can avoid the static JSON fixture files that Django recommends you use in tests by default. Factories are also general purpose - they just generate data and use it to create a model - and so they can be re-used to fill your development database rather than dumping from production. The problem Here’s a typical test case: class MyTests(TestCase): fixtures = ['basic.json'] def setUp(self): self.user = User.objects.create( username='adam', first_name='Adam', last_name='Johnson', email='adam@example.com' ) # do some testing ... We have test data in two places with different maintenance strategies - ouch. Firstly, the ‘basic.json’ file contains JSON objects with data to be passed to the model constructor; and secondly, the call to User.objects.create which contains data in a different format. Also, it’s really hard to tell which bits of the data the test depends on, since the fixtures are shared between tests, and to call create on a model … -
Factory Boy Fun
I've recently been working on improving the test suite at YPlan. The biggest change is moving towards dynamic fixtures for our Django models using “Factory Boy”. This library is essentially a tool that lets you define simple helper functions to generate random, sensible model instances quickly; by using them in tests you can avoid the static JSON fixture files that Django recommends you use in tests by default. Factories are also general purpose - they just generate data and use it to create a model - and so they can be re-used to fill your development database rather than dumping from production. The problem Here's a typical test case: class MyTests(TestCase): fixtures = ['basic.json'] def setUp(self): self.user = User.objects.create( username='adam', first_name='Adam', last_name='Johnson', email='adam@example.com' ) # do some testing ... We have test data in two places with different maintenance strategies - ouch. Firstly, the 'basic.json' file contains JSON objects with data to be passed to the model constructor; and secondly, the call to User.objects.create which contains data in a different format. Also, it's really hard to tell which bits of the data the test depends on, since the fixtures are shared between tests, and to call create on a model … -
Factory Boy Fun
I've recently been working on improving the test suite at YPlan. The biggest change is moving towards dynamic fixtures for our Django models using “Factory Boy”. This library is essentially a tool that lets you define simple helper functions to generate random, sensible model instances quickly; by using them in tests you can avoid the static JSON fixture files that Django recommends you use in tests by default. Factories are also general purpose - they just generate data and use it to create a model - and so they can be re-used to fill your development database rather than dumping from production. The problem Here's a typical test case: class MyTests(TestCase): fixtures = ['basic.json'] def setUp(self): self.user = User.objects.create( username='adam', first_name='Adam', last_name='Johnson', email='adam@example.com' ) # do some testing ... We have test data in two places with different maintenance strategies - ouch. Firstly, the 'basic.json' file contains JSON objects with data to be passed to the model constructor; and secondly, the call to User.objects.create which contains data in a different format. Also, it's really hard to tell which bits of the data the test depends on, since the fixtures are shared between tests, and to call create on a model … -
Geo+Django: Geo Beyond the Django slides
Geo+Django: Geo Beyond the Django slides -
New Django Server Setup: Part 1
New Django Server Setup: Part 1 -
Django Internationalization
Django Internationalization -
Upgrades: Django Old to Django New
Upgrades: Django Old to Django New -
Simple Job Queues with django_rq
Simple Job Queues with django_rq -
Imaginary hosts The Onion for a video shoot
Imaginary hosts The Onion for a video shoot -
DjangoCon Performance Optimization Slides
DjangoCon Performance Optimization Slides -
Twelve-Factor Renaissance
Twelve-Factor Renaissance -
Debug Toolbar Primer
Debug Toolbar Primer -
My First Django Sprint
My First Django Sprint -
Getting Started Contributing to Django
Getting Started Contributing to Django -
Django and IPython Notebook
Django and IPython Notebook -
Postgres VIEW meet Django Model
[Postgres](http://www.postgresql.org) `VIEW`s are a nice way to store a subset of a table in a way that can itself be queried, or perhaps slightly or radically changing the shape of your table. It has a fairly simple syntax: {% highlight sql %} CREATE VIEW "foo" AS SELECT "bar", "baz", "qux" FROM "corge" WHERE "grault" IS NULL; {% endhighlight %} You may use any valid `SELECT` query as the source of a `VIEW`, including one that contains `UNION` or `UNION ALL`. You can use this form to create a view that takes two similarly formatted tables and combines them into one logical table. Note that for a `UNION` to work, the columns (and column types) must be identical between the two parts of the query. A `UNION` will do extra work to ensure all rows are unique: `UNION ALL` may perform better, especially if you know your rows will be unique (or you need duplicates). By default, a Postgres `VIEW` is dynamic, and read-only. With the use of the `CREATE MATERIALIZED VIEW` form, it's possible to have a cached copy stored on disk, which requires an `UPDATE MATERIALIZED VIEW "viewname"` in order to cause an update. It's also possible to create … -
Django & Rails - another year another comparison
It is the time of the year where I start talking about Django and Ruby on Rails. Since my last two posts I received many questions about this topic and the old posts are still read frequently and quoted. So let me bring you up to date what changed, what improved since the last post and which framework is the best choice. If you did not read my last two posts about this topic I suggest you read them now. I will make claims and statements in this post I already elaborated in them and without the context they can be quite controversial. To the disappointment of some of you: this is still not Django vs Rails - it is no discussion that will come to the conclusion that there is a holy grail of frameworks, totally destroying one of them with arguments why the other one is so superior. While Django is slowly moving towards migrations being part of the core functionality Ruby on Rails just added support for real foreign keys support. Django 1.7, which will bring you the joy of migrations, is currently not marked as stable, but release candidate two makes a good impression and it … -
Django & Rails - another year another comparison
Django & Rails - another year another comparison It is the time of the year where I start talking about Django and Ruby on Rails. Since my last two posts I received many questions about this topic and the old posts are still read frequently and quoted. So let me bring you up to date what changed, what improved since the last post and which framework is the best choice. If you did not read my last two posts about this topic I suggest you read them now. I will make claims and statements in this post I already elaborated in them and without the context they can be quite controversial. To the disappointment of some of you: this is still not Django vs Rails - it is no discussion that will come to the conclusion that there is a holy grail of frameworks, totally destroying one of them with arguments why the other one is so superior. While Django is slowly moving towards migrations being part of the core functionality Ruby on Rails just added support for real foreign keys support. Django 1.7, which will bring you the joy of migrations, is currently not marked as stable, but release … -
Creating a re-usable Django app - Part 1
Hi everyone and welcome back for this next tutorial of the Babbler series. This tutorial will cover 2 ways of creating a re-usable Django app. The first and simplest one is apps for flexible and personal re-use. The second one is a somewhat less simple way of doing it but which allows re-distribution of your application and that can be a very good thing too! For the first part of this tutorial we will be using the custom user model, built during the previous tutorial, as a starting point. The second part will be using the theme application built during the Using your own flavour of bootstrap with django tutorial. -
Avoiding SQL Antipatterns using Django (and Postgres)
The book [SQL Antipatterns](http://pragprog.com/book/bksqla/sql-antipatterns) is one of my favourite books. I took the opportunity to reread it on a trip to [Xerocon](https://www.xero.com/au/xerocon/sydney/) in Sydney, and as usual it enlightened me to thing I am probably doing in my database interactions. So, I'm going to look at these Antipatterns, and discuss how you can avoid them when using [Django](https://ww.django project.com). This post is intended to be read with each chapter of the book. I've used the section headings, but instead of the chapter headings, I've used the Antipattern headings. They are still in the same order, though. It seems the printed version of this book is on sale now: I'm tempted to buy a few extra copies for gifts. Ahem, cow-orkers. Logical Database Design Antipatterns ¶ Format Comma-Separated Lists ¶ This one is pretty simple: use a relation instead of a [Comma Separated field](https://docs.djangoproject.com/en/1.7/ref/models/fields/#commaseparatedintegerfield). In the cases described in the book, a [`ManyToManyField`](https://docs.djangoproject.com/en/1.7/ref/models/fields/#manytomanyfield) is in fact simpler than a Comma Separated field. Django gets a gold star here, both in ease of use, but also in documentation about relations. However, there may be times when a relation is overkill, and a real array is better. For instance, when storing data related … -
Django Templating Language - Part I
Hey guys! I know I haven't posted anything in a very long time. Exigent circumstances. Anyway, now I'm back with what may well be the most important skill in your entire Django toolkit. The templating language that Django ships makes writing pages that display multiple results mundanely easy.In this part I'll only introduce you to templates. We'll see how to render them in the next one.Variables:We all know what variables are and how important they are for programming. This is how variables are represented in Django:{{ variable_name }}It can also be written as {{variable_name}} but the former is more readable. Let's see how to 'declare' a variable in an HTML script:<h1>{{ heading }}</h1><form action = "/foo/" method = "post"> <input type = "text" name = "bar" placeholder = "{{ placeholder }}"></form>Notice the difference? {{ heading }} is without quotes and {{ placeholder }} is with. The basic concept is you write the name of the variable exactly as you would write normal text. While writing normal text, you would not put quotes between the <h1>...</h1> tags but would in the <input> tag.Right now if you just write this much code it'll print all raw data. There is no use … -
Chaussette and Circus as a new way to deploy your Django applications
Many Python web applications run on production with the help of gunicorn or uwsgi. There are however other solutions that may turn out to be even better than the currently popular solutions. One of alternatives is chaussette and circus. Chaussette is a WSGI server that can serve WSGI applications like your Django project. Circus is an application to control and monitor processes and sockets. It can manage chaussette, celery or other sockets and processes making it a manager of all project services. -
What's New With WhisperGifts
In the past couple of months I've done some fun and interesting stuff over at WhisperGifts, my side project that lets couples put their bridal gift registry online. It's all built with Django, so I thought I'd share a few neat things I've come across along the way. Bookmarket and …