Package: django-currencies
django-currencies allows you to define different currencies, and
includes template tags/filters to allow easy conversion between them.For more details, see thedocumentationat Read The Docs.Authored byPanos Laganakos, and some greatcontributors.InstallationEither clone this repository into your project, or install withpip:pipinstalldjango-currenciesYou’ll need to addcurrenciestoINSTALLED_APPSin your project’s
settings file:importdjangoINSTALLED_APPS+=('currencies',)ifdjango.VERSION<(1,7):INSTALLED_APPS+=('south',)Either have thecurrencies.context_processors.currenciesprocessor:TEMPLATE_CONTEXT_PROCESSORS+=('django.core.context_processors.request',# must be enabled'currencies.context_processors.currencies',)Or use the template tagcurrency_context:{%loadcurrency%}{%currency_context%}Update yoururls.pyfile :urlpatterns+=patterns('',url(r'^currencies/',include('currencies.urls')),)Then run./manage.py migrateto create the required database tablesUpgrading from 0.3.3Upgrading from 0.3.3 is likely to cause problems trying to apply a
migration when the tables already exist. In this case a fake migration
needs to be applied:./manage.pymigratecurrencies0001--fakeConfigurationdjango-currencies has built-in integration withopenexchangerates.org,Yahoo FinanceandCurrency ISO.Management CommandsYou can use the management commandscurrenciesandupdatecurrenciesto maintain the currencies in the database. The former will import any
currencies that are defined on the selected source into the database.
This includes information like the currency code, name, symbol, and any
other info provided. The latter will update all the database currency
rates from the source. Any currency missing on the source will be untouched.You can selectively import currencies, for example the commands below
will import USD and EUR currencies only, or use a variable from the
settings that points to an iterable respectively:./manage.pycurrencies--import=USD--import=EUR./manage.pycurrencies-iSHOP_CURRENCIESThe command automatically looks for variables CURRENCIES or SHOP_CURRENCIES
in settings if-iis not specified.
For more information on the additional switches--forceand--verbositytry./manage.py help currencies.updatecurrenciescan automatically change the base rate of the imported
exchange rates by specifying the--baseswitch like so:./manage.pyupdatecurrenciesoxr--base=USD./manage.pyupdatecurrenciesyahoo-bSHOP_DEFAULT_CURRENCYThe command automatically looks for variables CURRENCIES_BASE or
SHOP_DEFAULT_CURRENCY in settings if-bis not specified.OpenExchangeRatesThis is the default source or select it specifically usingoxras
positional argument to either command.You will need to specify your API key in your settings file:OPENEXCHANGERATES_APP_ID="c2b2efcb306e075d9c2f2d0b614119ea"Requirements:requests(python3-compatible fork ofOpenExchangeRatesClientis integrated due to abandoned project)Yahoo FinanceAttention!Yahoo integration is now deprecated due to withdrawal of the service around 6 Feb 2018 due to purchase by Verizon.
The cached currency json file will continue to be available through thecurrenciescommand however.Select this source by specifyingyahooas positional argument.Requirements:BeautifulSoup4andrequestsCurrency ISOSelect this source by specifyingisoas positional argument.Requirements:requestsIntegrationLive FeedsCurrenciesRatesSymbolsOther Infooxr✅✅✅ *yahoo✅✘✅✅iso✅✅* Symbols are imported from the filecurrencies.jsonbecause it is notsupported by the service. Other info includes ISO4217 number and exponent,country and city names, and alternative
currency names.UsageFirst of all, load thecurrencyin every template where you want to use it:{%loadcurrency%}Use:{%change_currency[price][currency_code]%}for example:{%change_currencyproduct.price"USD"%}<!-- or if you have the ``currencies.context_processors.currencies`` available -->{%change_currencyproduct.priceCURRENCY.code%}or use the filter:{{[price]|currency:[currency_code]}}for example:{{product.price|currency:"USD"}}or set theCURRENCY_CODEcontext variable with aPOSTto the included
view:{%url'currencies_set_currency'[currency_code]%}or use the template tagcurrency_context:{%currency_context%}which gives the three context variables:CURRENCIES,CURRENCY_CODEandCURRENCY.TemplateIncluded is a template for a Bootstrap 3 & fontawesome compatible navbar
currency chooser. The navbar item will display if there are more than 1 active
currencies. There is a navbar parameterdropdown_extra_classwhich is used
to supply extra classes to the dropdown:{%blocknavbar-nav%}...<ulclass="nav navbar-nav navbar-right">...{%withdropdown_extra_class="collapsed-nav"%}{%include"currencies/navbar/currency-chooser-bs3fa.html"%}{%endwith%}Attention!The currency choice may not be reflected on the navbar if your view is not re-rendered.
This may be the case if you are viewing a default page in Django CMS for example.
This is due to the context processor not being triggered because the RequestContext
is not re-generated.Licensedjango-currenciesis released under the BSD license.