Python and Django

12 Jan, 17

There's Wagtail CMS Admin Styleguide Available

In case you didn't know and always been wondering about the next wagtail admin icon class, there's Wagtail CMS admin styleguide which comes with core packages. To enable it just update your INSTALLED_APPS config:

1
2
3
4
5
  1. INSTALLED_APPS = [
  2. ...
  3. 'wagtail.contrib.wagtailstyleguide',
  4. ...
  5. ]

And you're ready to access the guide ...

Read now
07 Oct, 16

"Error loading MySQLdb module Reason: image not found" error fix in El Capitan Mac OS

If you use mysql database in your Django project and when you run runserver command and get an error message similar to this: "Error loading MySQLdb module Reason: image not found" that means your El Capitan struggles to find necessary libraries. 

The issue can be fixed with these two ...

Read now
16 Sep, 16

Installing cryptography (part of Scrapy) on Mac OS X

I'm leaving this tip as a note for myself, but I hope someone will find it useful too.

If you try to install Scrapy or cryptography on Mac OS X, your pip install will likely fail with the message similar to this:

1
2
3
4
5
6
7
8
9 ...
Read now
30 Jun, 15

Creating Custom Template Filter That Injects Adsense Ad Code After N Paragraph in Django

Injecting ads inside content is a very effective technique. Let's say you want to inject Adsense ad after the first paragraph of text. To add such capability to our Django-based website we need to create a custom filter for that. I'll tell you how to implement such a filter.

1 ...

Read now
06 May, 15

Running Django manage.py commands from anywhere

One of the most annoying aspects of developing in Django for me is running manage.py commands: you need to be in the same directory with manage.py file in order to run a command. This is not convenient. I thought it would be cool to be able to run ...

Read now
01 May, 15

Installing libsass (django_libsass) on Mac OS Yosemite

I started playing with wagtail recently (a very promisiing Django CMS) and they use django_libsass to compile their sass into css. Unfortunatelly, if you'll try to install django libsass via PIP on Mac you'll get a compile error message. I tried lots of approaches to fix this and it didn't ...

Read now
29 Apr, 15

Saving file field uploads not in MEDIA_ROOT directory

I had a requirement recently to upload files to some kind of a private directory, not accessible via www. Of course, I used Django model's FileField to solve the task, but the problem was in a fact that by default, FileField saves uploads under MEDIA_ROOT which is not what I ...

Read now
21 Oct, 14

Django Uwsgi Nginx 504 Gateway Timeout

I had a long running process (data import) and encountered 504 Gateway Timeout error. I use Nginx / uwsgi pair to serve my Django app. After doing some research it turned out that the problem is in uwsgi_read_timeout directive. Directive sets the amount of time for upstream to wait for a ...

Read now
09 Oct, 14

AngularJS plus Django: A match made in heaven

I've just finished watching "AngularJS plus Django: A match made in heaven" DjangoCon US 2014 talk by Nina Zakharenko (Video | Slides) and it was quite helpful. Since I'm working with API's and mobile / angular apps a lot, I just made some helpful Django + AngularJS related notes that came out of ...

Read now
19 Sep, 14

Improving Number of Queries Generated by Django Comment's render_comment_list Template Tag

One of my Django apps uses Django Comments. To show a list of comments on a page I use this simple built-in template tag:

1
  1. {% render_comment_list for object %}

All is fine, but I noticed that it loads user object per every comment line. So if you have 50 comments on ...

Read now