Re: [django-oscar] NoneType object has no attribute currency_formats

1,619 views
Skip to first unread message

David Winterbottom

unread,
Jan 3, 2013, 9:28:23 AM1/3/13
to django...@googlegroups.com
This is related to locales.  

It seems Babel (the package Oscar uses for currency formatting) can't find a locale for your system.  It may be worth playing around with Babel in isolation to see if you can recreate the problem when you format a currency.  Maybe you need to configure your OS in some way to provide a locale.

I'm not a Windows user and don't have any experience here.

More broadly, Oscar is aimed at linux, mac users - not windows.  There may well be other problems with running Oscar on Windows.  If it's palatable, I suggest using a linux box to develop on Oscar.  You could use Vagrant (http://vagrantup.com/ [homepage is down right now]) - Oscar ships with a VagrantFile that will provision a virtual machine correctly:

Good luck!

On 2 January 2013 23:16, <val...@valsor.com> wrote:
Hi,

First of all many thanks Oscar's developers for making Oscar public. It looks very promising!

I'm in process of switching from PHP to Python and looking for some decent e-commerce framework. At the moment I'm new to Python and Django but have solid background in ASP.NET and PHP. I've installed Sandbox demo app on Windows machine following documentation as close as possible. As there is no 'make' command on Windows I ran appropriate commands from Makefile manually. It seems everything installed smoothly. But after I started server and tried to access homepage I got error (see bellow). Does anybody have some ideas on how to fix it? I'm on Windows XP. Any advice will be appreciated.

vs

AttributeError at /

'NoneType' object has no attribute 'currency_formats'
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.4.3
Exception Type:AttributeError
Exception Value:

'NoneType' object has no attribute 'currency_formats'
Exception Location: C:\Program Files\Python27\lib\site-packages\babel-0.9.6-py2.7.egg\babel\numbers.py in format_currency, line 200
Python Executable:C:\Program Files\Python27\python.exe
Python Version:2.7.3
Python Path:
['D:\\Projects\\Librica\\Vendor\\django_oscar\\sites\\sandbox',
 'C:\\Program Files\\Python27\\lib\\site-packages\\pip-1.2.1-py2.7.egg',
 'd:\\projects\\librica\\vendor\\django_oscar',
 'C:\\Program Files\\Python27\\lib\\site-packages\\babel-0.9.6-py2.7.egg',
 'C:\\Program Files\\Python27\\lib\\site-packages\\python_memcached-1.48-py2.7.egg',
 'C:\\Program Files\\Python27\\lib\\site-packages\\sorl_thumbnail-11.12-py2.7.egg',
 'C:\\Program Files\\Python27\\lib\\site-packages\\django_treebeard-1.61-py2.7.egg',
 'C:\\Program Files\\Python27\\lib\\site-packages\\django_haystack-2.0.0_beta-py2.7.egg',
 'C:\\Program Files\\Python27\\lib\\site-packages\\django_extra_views-0.5.2-py2.7.egg',
 'C:\\Program Files\\Python27\\lib\\site-packages\\south-0.7.6-py2.7.egg',
 'C:\\Program Files\\Python27\\lib\\site-packages\\pil-1.1.7-py2.7-win32.egg',
 'C:\\Program Files\\Python27\\lib\\site-packages\\django-1.4.3-py2.7.egg',
 'C:\\WINDOWS\\system32\\python27.zip',
 'C:\\Program Files\\Python27\\DLLs',
 'C:\\Program Files\\Python27\\lib',
 'C:\\Program Files\\Python27\\lib\\plat-win',
 'C:\\Program Files\\Python27\\lib\\lib-tk',
 'C:\\Program Files\\Python27',
 'C:\\Program Files\\Python27\\lib\\site-packages']
Server time: Thu, 3 Jan 2013 02:09:05 +0400

Error during template rendering

In template d:\projects\librica\vendor\django_oscar\oscar\templates\oscar\partials\brand.html, error at line 18

'NoneType' object has no attribute 'currency_formats'

8 <div class="btn-group">
9 <a class="btn" href="{% url basket:summary %}">{% trans "View Basket" %}</a>
10 <button class="btn dropdown-toggle" data-toggle="dropdown">
11 <span class="caret"></span>
12 </button>
13 <ul class="dropdown-menu pull-right">
14 <li>{% include "basket/partials/basket_quick.html" %}</li>
15 </ul>
16 </div>
17 </li>
18 <li class="cart_summary"><strong>{% trans "Basket total:" %} <span>{{ request.basket.total_incl_tax|currency }}</span></strong></li>
19 </ul><!-- /cart -->
20 {% endif %}

Environment:


Request Method: GET

Django Version: 1.4.3
Python Version: 2.7.3
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.admin',
 'django.contrib.flatpages',
 'django.contrib.staticfiles',
 'django_extensions',
 'debug_toolbar',
 'south',
 'rosetta',
 'apps.user',
 'apps.gateway',
 'oscar',
 'oscar.apps.analytics',
 'oscar.apps.order',
 'oscar.apps.checkout',
 'oscar.apps.shipping',
 'oscar.apps.catalogue',
 'oscar.apps.catalogue.reviews',
 'oscar.apps.basket',
 'oscar.apps.payment',
 'oscar.apps.offer',
 'oscar.apps.address',
 'oscar.apps.partner',
 'oscar.apps.customer',
 'oscar.apps.promotions',
 'oscar.apps.search',
 'oscar.apps.voucher',
 'oscar.apps.dashboard',
 'oscar.apps.dashboard.reports',
 'oscar.apps.dashboard.users',
 'oscar.apps.dashboard.orders',
 'oscar.apps.dashboard.promotions',
 'oscar.apps.dashboard.catalogue',
 'oscar.apps.dashboard.offers',
 'oscar.apps.dashboard.ranges',
 'oscar.apps.dashboard.vouchers',
 'oscar.apps.dashboard.communications',
 'haystack',
 'treebeard',
 'sorl.thumbnail']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.transaction.TransactionMiddleware',
 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
 'debug_toolbar.middleware.DebugToolbarMiddleware',
 'oscar.apps.basket.middleware.BasketMiddleware')


Template error:
In template d:\projects\librica\vendor\django_oscar\oscar\templates\oscar\partials\brand.html, error at line 18
   'NoneType' object has no attribute 'currency_formats'
   8 : <div class="btn-group">


   9 : <a class="btn" href="{% url basket:summary %}">{% trans "View Basket" %}</a>


   10 : <button class="btn dropdown-toggle" data-toggle="dropdown">


   11 : <span class="caret"></span>


   12 : </button>


   13 : <ul class="dropdown-menu pull-right">


   14 : <li>{% include "basket/partials/basket_quick.html" %}</li>


   15 : </ul>


   16 : </div>


   17 : </li>


   18 : <li class="cart_summary"><strong>{% trans "Basket total:" %} <span> {{ request.basket.total_incl_tax|currency }} </span></strong></li>


   19 : </ul><!-- /cart -->


   20 : {% endif %}

Traceback:
File "C:\Program Files\Python27\lib\site-packages\django-1.4.3-py2.7.egg\django\core\handlers\base.py" in get_response
  136.                     response = response.render()
File "C:\Program Files\Python27\lib\site-packages\django-1.4.3-py2.7.egg\django\template\response.py" in render
  104.             self._set_content(self.rendered_content)
File "C:\Program Files\Python27\lib\site-packages\django-1.4.3-py2.7.egg\django\template\response.py" in rendered_content
  81.         content = template.render(context)
File "C:\Program Files\Python27\lib\site-packages\django-1.4.3-py2.7.egg\django\template\base.py" in render
  140.             return self._render(context)
File "C:\Program Files\Python27\lib\site-packages\django-1.4.3-py2.7.egg\django\test\utils.py" in instrumented_test_render
  62.     return self.nodelist.render(context)
File "C:\Program Files\Python27\lib\site-packages\django-1.4.3-py2.7.egg\django\template\base.py" in render
  823.                 bit = self.render_node(node, context)
File "C:\Program Files\Python27\lib\site-packages\django-1.4.3-py2.7.egg\django\template\debug.py" in render_node
  74.             return node.render(context)
File "C:\Program Files\Python27\lib\site-packages\django-1.4.3-py2.7.egg\django\template\loader_tags.py" in render
  123.         return compiled_parent._render(context)
File "C:\Program Files\Python27\lib\site-packages\django-1.4.3-py2.7.egg\django\test\utils.py" in instrumented_test_render
  62.     return self.nodelist.render(context)
File "C:\Program Files\Python27\lib\site-packages\django-1.4.3-py2.7.egg\django\template\base.py" in render
  823.                 bit = self.render_node(node, context)
File "C:\Program Files\Python27\lib\site-packages\django-1.4.3-py2.7.egg\django\template\debug.py" in render_node
  74.             return node.render(context)
File "C:\Program Files\Python27\lib\site-packages\django-1.4.3-py2.7.egg\django\template\loader_tags.py" in render
  123.         return compiled_parent._render(context)
File "C:\Program Files\Python27\lib\site-packages\django-1.4.3-py2.7.egg\django\test\utils.py" in instrumented_test_render
  62.     return self.nodelist.render(context)
File "C:\Program Files\Python27\lib\site-packages\django-1.4.3-py2.7.egg\django\template\base.py" in render
  823.                 bit = self.render_node(node, context)
File "C:\Program Files\Python27\lib\site-packages\django-1.4.3-py2.7.egg\django\template\debug.py" in render_node
  74.             return node.render(context)
File "C:\Program Files\Python27\lib\site-packages\django-1.4.3-py2.7.egg\django\template\loader_tags.py" in render
  123.         return compiled_parent._render(context)
File "C:\Program Files\Python27\lib\site-packages\django-1.4.3-py2.7.egg\django\test\utils.py" in instrumented_test_render
  62.     return self.nodelist.render(context)
File "C:\Program Files\Python27\lib\site-packages\django-1.4.3-py2.7.egg\django\template\base.py" in render
  823.                 bit = self.render_node(node, context)
File "C:\Program Files\Python27\lib\site-packages\django-1.4.3-py2.7.egg\django\template\debug.py" in render_node
  74.             return node.render(context)
File "C:\Program Files\Python27\lib\site-packages\django-1.4.3-py2.7.egg\django\template\loader_tags.py" in render
  62.             result = block.nodelist.render(context)
File "C:\Program Files\Python27\lib\site-packages\django-1.4.3-py2.7.egg\django\template\base.py" in render
  823.                 bit = self.render_node(node, context)
File "C:\Program Files\Python27\lib\site-packages\django-1.4.3-py2.7.egg\django\template\debug.py" in render_node
  74.             return node.render(context)
File "C:\Program Files\Python27\lib\site-packages\django-1.4.3-py2.7.egg\django\template\loader_tags.py" in render
  155.         return self.render_template(self.template, context)
File "C:\Program Files\Python27\lib\site-packages\django-1.4.3-py2.7.egg\django\template\loader_tags.py" in render_template
  137.         output = template.render(context)
File "C:\Program Files\Python27\lib\site-packages\django-1.4.3-py2.7.egg\django\template\base.py" in render
  140.             return self._render(context)
File "C:\Program Files\Python27\lib\site-packages\django-1.4.3-py2.7.egg\django\test\utils.py" in instrumented_test_render
  62.     return self.nodelist.render(context)
File "C:\Program Files\Python27\lib\site-packages\django-1.4.3-py2.7.egg\django\template\base.py" in render
  823.                 bit = self.render_node(node, context)
File "C:\Program Files\Python27\lib\site-packages\django-1.4.3-py2.7.egg\django\template\debug.py" in render_node
  74.             return node.render(context)
File "C:\Program Files\Python27\lib\site-packages\django-1.4.3-py2.7.egg\django\template\defaulttags.py" in render
  281.                 return nodelist.render(context)
File "C:\Program Files\Python27\lib\site-packages\django-1.4.3-py2.7.egg\django\template\base.py" in render
  823.                 bit = self.render_node(node, context)
File "C:\Program Files\Python27\lib\site-packages\django-1.4.3-py2.7.egg\django\template\debug.py" in render_node
  74.             return node.render(context)
File "C:\Program Files\Python27\lib\site-packages\django-1.4.3-py2.7.egg\django\template\debug.py" in render
  84.             output = self.filter_expression.resolve(context)
File "C:\Program Files\Python27\lib\site-packages\django-1.4.3-py2.7.egg\django\template\base.py" in resolve
  599.                 new_obj = func(obj, *arg_vals)
File "d:\projects\librica\vendor\django_oscar\oscar\templatetags\currency_filters.py" in currency
  27.     return format_currency(value, **kwargs)
File "C:\Program Files\Python27\lib\site-packages\babel-0.9.6-py2.7.egg\babel\numbers.py" in format_currency
  200.         format = locale.currency_formats.get(format)

Exception Type: AttributeError at /
Exception Value: 'NoneType' object has no attribute 'currency_formats'




--
https://github.com/tangentlabs/django-oscar
---
You received this message because you are subscribed to the Google Groups "django-oscar" group.
Visit this group at http://groups.google.com/group/django-oscar?hl=en-US.
 
 



--
David Winterbottom
Head of Programming

Tangent Labs
84-86 Great Portland Street
London W1W 7NR
England, UK

Anton Yanchenko

unread,
Jan 3, 2013, 9:45:27 AM1/3/13
to django...@googlegroups.com
2013/1/3 David Winterbottom <david.win...@tangentlabs.co.uk>
> This is related to locales.
>
> It seems Babel (the package Oscar uses for currency formatting) can't find
> a locale for your system. It may be worth playing around with Babel in
> isolation to see if you can recreate the problem when you format a currency.
> Maybe you need to configure your OS in some way to provide a locale.
Settings of environment variable LANG=ru_RU.UTF-8 helped me. But those
was on linux system.


--
Thanks,
Anton Yanchenko

val...@valsor.com

unread,
Jan 3, 2013, 10:27:32 AM1/3/13
to django...@googlegroups.com
Thanks. It helped me too. I added environment variable LANG=ru_RU.UTF-8 and babel error is gone.

Anton Yanchenko

unread,
Jan 3, 2013, 11:14:38 AM1/3/13
to django...@googlegroups.com
2013/1/3 <val...@valsor.com>:
> Thanks. It helped me too. I added environment variable LANG=ru_RU.UTF-8 and
> babel error is gone.
You are welcome. Just set instead of ru_RU your language and country
codes (en_US or whatever) and maybe another encoding if you are not
using utf8.


--
Thanks,
Anton Yanchenko

Mike Lee

unread,
Sep 13, 2013, 1:25:18 PM9/13/13
to django...@googlegroups.com, david.win...@tangentlabs.co.uk
I put the following on settings.py
OSCAR_DEFAULT_CURRENCY = 'USD'
OSCAR_CURRENCY_LOCALE = 'en_US'

after that, it works fine for me.

Maik Hoepfel

unread,
Sep 18, 2013, 5:06:03 AM9/18/13
to django...@googlegroups.com, david.win...@tangentlabs.co.uk
It's not the first time I've run into this issue. I created an issue so that somebody has a closer look: https://github.com/tangentlabs/django-oscar/issues/837

aamir hussain

unread,
Oct 2, 2013, 4:20:48 PM10/2/13
to django...@googlegroups.com, david.win...@tangentlabs.co.uk
The first error after running the oscar is this error.
But fortunately found a very simple and easy way out .i.e include 

OSCAR_DEFAULT_CURRENCY and  OSCAR_CURRENCY_LOCALE
in your settings. For me it was 

OSCAR_DEFAULT_CURRENCY = 'AED'
OSCAR_CURRENCY_LOCALE = 'ar_AE'

it works fine ,all the error disappeared but the currency symbol is not displayed correctly.

Izidor Matušov

unread,
Oct 3, 2013, 5:29:38 AM10/3/13
to django...@googlegroups.com
Hi Aamir,

I don't know what is the correct symbol to display but in the end, you
end up running this code:

In [1]: from babel.numbers import format_currency

In [2]: format_currency(5.99, currency='AED', locale='ar_AE')
Out[2]: u'\u062f.\u0625.\u200f\xa05\u066b99'

In [3]: print format_currency(5.99, currency='AED', locale='ar_AE')
د.إ.‏ 5٫99

It's displayed differently in the email editor and my terminal (see
attachment)

What is the correct representation of currency for AED?

You might want to play with the OSCAR_CURRENCY_FORMAT which maps into
babel format parameter:

http://babel.pocoo.org/docs/api/numbers/#babel.numbers.format_currency
2013-10-03_10:22:13.png

Maik Hoepfel

unread,
Nov 14, 2013, 11:10:49 AM11/14/13
to django...@googlegroups.com, izidor....@tangentsnowball.com
Reply all
Reply to author
Forward
0 new messages