Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

NameError: name 'urlpatterns' is not defined using i18n_patterns

I have problems writing the urls for translation. According to this question I understand that it is because I have += so I need to put this = the bad thing is that I have to translate all my urls I can’t leave any outside of i18n, what can I do to include all my urls there?

from . import views
from django.urls import path
from django.conf.urls.i18n import i18n_patterns

app_name='Clientes'


urlpatterns+= i18n_patterns(
    path('',views.list_clientes,name='clientes_list'),
    path('add',views.create_clientes.as_view(),name='clientes_add'),
    path('edit/<int:pk>',views.edit_clientes.as_view(),name='clientes_edit'),
    path('<int:pk>/',views.detail_clientes.as_view(),name='clientes_detail'),
    path('delete/<int:pk>',views.eliminar_cliente.as_view(),name='clientes_delete'),
)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You did not define urlpatterns before. If you want to translate all paths, you use:

#           🖟 assignment
urlpatterns = i18n_patterns(
    path('',views.list_clientes,name='clientes_list'),
    path('add',views.create_clientes.as_view(),name='clientes_add'),
    path('edit/<int:pk>',views.edit_clientes.as_view(),name='clientes_edit'),
    path('<int:pk>/',views.detail_clientes.as_view(),name='clientes_detail'),
    path('delete/<int:pk>',views.eliminar_cliente.as_view(),name='clientes_delete'),
)

In the linked answer, it first defines a list, and then extends it with +=, exactly because not all url patterns are translated there. But if all patterns should be translated, you assign the result of i18n_patterns(..) to the urlpatterns.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading