I am programming a website in Django I want to put the Arabic language in my link, but when I make the link in Arabic and when I choose it, it takes me to the page page not found Note: This only happens on the hosting server, meaning it does not happen on localhost
urls.py
from django.urls import path, re_path
from . import views
urlpatterns = [
# pages
path('',views.index,name='index'),
path('الصفحة/',views.listArticle,name='listArticle'),
path('TravelTips/',views.TravelTips,name='TravelTips'),
# view article
path('الصفحة/<str:slug_url>/', views.view_article, name='Page_Article'),
path('TravelTips/<str:slug_url>/',views.view_article,name='Page_Article'),
,]
I expected that the problem was in the slug, but it turned out that Django in general did not accept Arabic letters
When using Django to handle Arabic language in URLs or links, there are a few considerations to keep in mind to ensure proper functionality and compatibility.
urlquotefunction to properly encode non-ASCII characters for URLs. Here's an example:Localization Middleware: Django's
LocaleMiddlewareshould be enabled in your project's middleware settings. This middleware handles language preferences, including Arabic, based on the user's browser settings.Language and Locale Configuration: In your Django project settings, make sure to set the appropriate language and locale settings. This includes specifying the
LANGUAGE_CODEandLOCALE_PATHS. For Arabic, theLANGUAGE_CODEwould be 'ar' for Modern Standard Arabic or 'ar-xx' for a specific Arabic variant (e.g., 'ar-sa' for Saudi Arabian Arabic).URL Patterns and Views: When defining URL patterns in your Django
urls.pyfile, you can include parameters that capture the Arabic text as variables in the URL. For example:In your view function
arabic_view, you can access the captured Arabic text as a parameter.It's important to note that while Django supports Arabic language handling, it's still crucial to ensure the proper configuration of your web server, database, and client-side settings to handle Unicode and text directionality correctly.