How to populate self._reverse_dict with a default language code ?

已查看 136 次
跳至第一个未读帖子

Etienne Robillard

未读,
2016年9月14日 10:42:332016/9/14
收件人 Django users
Hi,

Is there a way to populate self._reverse_dict to contain a default language_code in case
the setting USE_I18N is set to False?

See: http://dpaste.com/3Q1NHXA

Regards,

Etienne


Mike Dewhirst

未读,
2016年9月14日 20:34:042016/9/14
收件人 django...@googlegroups.com
On 14/09/2016 11:43 PM, Etienne Robillard wrote:
> Hi,
>
> Is there a way to populate self._reverse_dict to contain a default
> language_code in case
> the setting USE_I18N is set to False?

return self._reverse_dict.get("language_code", defaultlanguagecode)

or

try:
languagecode = failing_routine()
except KeyError:
languagecode = defaultlanguagecode




>
> See: http://dpaste.com/3Q1NHXA
>
> Regards,
>
> Etienne
>
>
> --
> 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...@googlegroups.com
> <mailto:django-users...@googlegroups.com>.
> To post to this group, send email to django...@googlegroups.com
> <mailto:django...@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/6453984f-999c-4404-916e-31bb9c7f69d8%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/6453984f-999c-4404-916e-31bb9c7f69d8%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

Etienne Robillard

未读,
2016年9月18日 09:07:522016/9/18
收件人 django...@googlegroups.com
Hi,

Actually the issue is that the self._reverse_dict type isn't containing
any key.

Mike Dewhirst

未读,
2016年9月18日 19:15:382016/9/18
收件人 django...@googlegroups.com
On 18/09/2016 11:07 PM, Etienne Robillard wrote:
> Hi,
>
> Actually the issue is that the self._reverse_dict type isn't
> containing any key.

You will need to examine class RegexURLResolver(LocaleRegexProvider) in
django/core/urlresolver.py where self._reverse_dict is declared and
populated to see where your problem might have arisen.

In that source you will see that self._reverse_dict is a dict and so
either of the suggestions below should work.

I suspect the language code you are looking for is not being properly
formatted. For example, in my settings.py I have LANGUAGE_CODE = 'en-au'
which seems to work for me so I think that is a reasonable format for it.

Cheers

Mike


>
>
>
> Le 2016-09-14 à 20:33, Mike Dewhirst a écrit :

Etienne Robillard

未读,
2016年9月19日 06:58:232016/9/19
收件人 django...@googlegroups.com
I created a ticket and patch for this issue:
https://code.djangoproject.com/ticket/27243

I guess my urlpatterns was improperly configured... However, the real
problem was that reverse() didn't

handle fully qualified module names.

Regards,

Etienne
--
Etienne Robillard
tka...@yandex.com
http://www.isotopesoftware.ca/

回复全部
回复作者
转发
0 个新帖子