- Go to settings.py file and
USE_I18N = True
USE_L10N = True
Go to middleware_classes section
add "'django.middleware.locale.LocaleMiddleware
"
- Create Template and write code
{%load i18n %}
{% trans "Hi I am Prashant Gaur" %} (you need to put all data in trans or any django template block) - Create language files:
go to project directory-
mkdir locale
django-admin.py makemessages -l en (english
django-admin.py makemessages -l sv (swedish)
If you are getting any error so it means you are missing xgettext (ubuntu)
sudo apt-get install gettext - python manage.py compilemessages
- Now change language in browser to swedish it will automatically convert into swedish .
- You can create many language files and multilingual environment is ready
Python, Django Framework, JavaScript, Lua, nginx, openresty, Apache,prashant, prashant gaur, gaur
Monday, 18 February 2013
Multilingual support in Django
add custom link href in django admin interface
Hi :)
step1 ) first go to your app folder and them select admin.py file
step 2 ) now
class Player(admin.ModelAdmin):
list_display =['id','Name','Mail','Facebook_link']
def facebook_link(self,obj):
return '<a href="%s">Facebook</a>'%('http://www.facebook.com')
facebook_link.allow_tags = True
facebook_link.short_dscription = "Facebook"
step1 ) first go to your app folder and them select admin.py file
step 2 ) now
class Player(admin.ModelAdmin):
list_display =['id','Name','Mail','Facebook_link']
def facebook_link(self,obj):
return '<a href="%s">Facebook</a>'%('http://www.facebook.com')
facebook_link.allow_tags = True
facebook_link.short_dscription = "Facebook"
Wednesday, 13 February 2013
find result after passing list in filter query in django
Like You have a Table Student with column "name"
so if you need to filter your object based in given list with some names .
Answer :
namelist =['first','second','third','fourth']
obj = Student.objects.filter(name__in=namelist)
so if you need to filter your object based in given list with some names .
Answer :
namelist =['first','second','third','fourth']
obj = Student.objects.filter(name__in=namelist)
Subscribe to:
Posts (Atom)