2

I'm currently using django 1.3 for my project. I'm working on the localization of the project. I'm able to localize the python code and templates, but I'm having trouble with the javascript localization. I'm getting TemplateSyntaxError message saying that "Caught NoReverseMatch while rendering: Reverse for ''django.views.i18n.javascript_catalog'' with arguments '()' and keyword arguments '{}' not found." I put the part of my url.py and the template home.html codes below. I checked django.views.i18n.javascript_catalog using python manage.py shell which is fine.

Can you tell me what I'm doing wrong?

Shouldn't url function in the template result in http:///jsi18n/?

Thanks!

Min

=== urls.py ===

js_info_dict = {
    'domain': 'djangojs',
    'packages': ('messages',),
}

urlpatterns = patterns('',

    url(r'^$', 'messages.views.home', name='home'),
    url(r'^messages/$', include('messages.urls')),

    # Localization
    url(r'^i18n/', include('django.conf.urls.i18n')),
    url(r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict),
)

=== end ===

=== home.html ===

<body>
    <script type="text/javascript" src="{% url 'django.views.i18n.javascript_catalog' %}"></script>
</body>

=== end ===

2 Answers 2

7

I finally found the reason for this error. The error is not related to the localization. If you change

<script... {% url 'django.views.i18n.javascript_catalog' %}"></script>

to

<script... {% url django.views.i18n.javascript_catalog %}"></script>

the error goes away.

Note that in urls.py, it is

url(r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict),

In short, in the html template file, no quotes around django.views.i18n.javascript_catalog whereas the the urls.py file, quotes around django.views.i18n.javascript_catalog. After this, I was able to get the javascript translation working.

Min

Sign up to request clarification or add additional context in comments.

1 Comment

This depends on whether you've written {% load url from future %} at the top of your template. I recommend including that snippet and quoting all your view paths. See the "Forwards compatibility" sidebar under the url tag documentation.
0

had the same error but found out that i had this:

url(r'^jsi18n/$', 'django.views.i18n.javascript_catalog',js_info_dict),
url(r'^i18n/', include('django.conf.urls.i18n')),

instead of this:

url(r'^i18n/', include('django.conf.urls.i18n')),
url(r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict),

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.