Django template translation not working as expected

2019-01-10 Thread Ashutosh Das
 

I am using django 2.1 , here is all the settings related to translation:


MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware',]

LANGUAGE_CODE = 'en'

LANGUAGES = (
('en', _('English')),
('bn', _('Bengali')))

LOCALE_PATH = (
os.path.join(BASE_DIR, 'locale'))

TIME_ZONE = 'Asia/Dhaka'

USE_I18N = True

USE_L10N = True

USE_TZ = False

Template tag that I want to translate:


{% load i18n %}
  {% trans "About Us" %}
{% get_current_language as LANGUAGE_CODE %}
{% if LANGUAGE_CODE == 'en' %}
ENGLISH
{% else %}
বাংলা
{% endif %}


ENGLISH
বাংলা

 


views.py :


def change_lan(request):
allowed_lan = ('en', 'bn')
get_lan = request.GET.get('lan', 'en')
if get_lan in allowed_lan:
translation.activate(get_lan)
request.session[translation.LANGUAGE_SESSION_KEY] = get_lan
return redirect(request.META.get('HTTP_REFERER', '/'))
else:
return redirect(request.META.get('HTTP_REFERER', '/'))

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3ed3c00a-148e-4817-a470-bada1af10ba3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Get newly created object id and then save the object in different DB?

2015-05-28 Thread Ashutosh Das


In Django function based view I can get newly created object id and again 
save that object to different database in this way :

data = Password(username=username, password=encrypted_pass,
  note=encrypted_note,added_at=timezone.now())
 data.save()
 Id = data.id
 data.pk = None
 data.save(using='backup')

But how can I do the same thing in Class based view ? Here is my view :

class AddData(LoggedInMixin, CreateView):
model = Password
success_url = '/dashboard'
template_name = 'forms/add.html'
fields = ['site_url', 'username', 'email', 'password', 'note']

def form_valid(self, form):
form.instance.added_at = timezone.now()
return super(AddData, self).form_valid(form)

def form_invalid(self, form):
return self.render_to_response(self.get_context_data(form=form))


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/042e6c2a-686f-4c00-89d7-7215589e22cf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Best way to learn Django considering Python versions and etc.

2013-12-11 Thread Ashutosh Das

Hi 
there  is a great book for Django http://www.tangowithdjango.com/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3a4cfa57-29ab-44f5-9c2f-95cc66e6c4c6%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.