This is what my urls.py looks like:
js_info_dict = {
'domain': 'djangojs',
'packages': ('project',),
}
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^', include('project.urls')),
url(r'^login/$', auth_views.login, {'template_name': 'login.html', 'authentication_form': LoginForm}, name = 'login'),
url(r'^logout/$', auth_views.logout, {'next_page': '/login'}),
url(r'^i18n/', include('django.conf.urls.i18n')),
]
urlpatterns += i18n_patterns('', (r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict), )
This is what I have in my html:
<script type="text/javascript" src="{% url 'django.views.i18n.javascript_catalog' %}"></script>
I have run django-admin makemessages -d djangojs -l fr
and made my changes to the djangojs.po
file. I then ran django-admin compilemessages
. I see the the djangojs.mo
file. When I go to my site, it is giving me an AttributeError that points to the line of HTML code above. How do I go about fixing this?
from django.conf.urls.i18n import i18n_patterns
js_info_dict = {
'domain': 'djangojs',
'packages': ('project',),
}
urlpatterns = i18n_patterns(
url(r'^jsi18n/$', js_info_dict, name='javascript-catalog'),
)
In template
`<script type="text/javascript" src="{% url 'javascript-catalog' %}">`</script>
For anyone else having this problem, this is what I did to solve the issue in addition to running django-admin makemessages -d djangojs -l fr
and django-admin compilemessages
.
urls.py should look like:
from django.views.i18n import JavaScriptCatalog
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^', include('project.urls')),
url(r'^login/$', auth_views.login, {'template_name': 'login.html', 'authentication_form': LoginForm}, name = 'login'),
url(r'^logout/$', auth_views.logout, {'next_page': '/login'}),
url(r'^i18n/', include('django.conf.urls.i18n')),
url(r'^jsi18n/$', JavaScriptCatalog.as_view(), name='javascript-catalog'),
]
This should be in template:
<script type="text/javascript" src="{% url 'javascript-catalog' %}"></script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.