when I use persian slug to get my post details I have a special problem…
in the pages with persian slug urls in the page start with corrent page address like this :
in the page : example.com/سلام-دنیا
when I click on the signUp button istead of this url: example.com/signUp
is example.com/سلام-دنیا/signUp
with english slug everything ok and working great
and whole this proccess is ok in the my localhost but on the cpanel host This problem occurs.
my urls.py posts app :
from django import urls
from django.urls import path , re_path
from . import views
urlpatterns = [
path('', views.posts , name='posts'),
path('new_post/', views.new_post , name='new_post'),
re_path(r'(?P<slug>[^/]+)/?
in my template:
<a class="btn btn-sm btn-outline-secondary" href="{%url "login"%}">عضویت/ورود</a>
my post function in views.py in posts app:
import os
from uuid import uuid4
from django.shortcuts import render , redirect
from django.contrib import messages
from config import settings
from posts.forms import CommentForm, PostCreatorFrom
from .decorators import user_is_superuser
from posts.utils import paginatePosts, searchPosts
from .models import Category, Comment, Post
from django.core.paginator import Paginator
from django.views.decorators.csrf import csrf_exempt
from django.http import JsonResponse
from pathlib import Path
from urllib.parse import unquote
from django.views.decorators.http import require_POST
from django.utils.text import slugify
from django.utils.encoding import uri_to_iri
def post(request, slug):
slug = uri_to_iri(slug)
postObj = Post.objects.get(slug=slug)
form = CommentForm()
category = postObj.category
related_posts = Post.objects.filter(category=category).exclude(slug=slug)[:3]
return render(request, 'posts/post.html', {'post': postObj, 'form': form , 'related_posts':related_posts})
and my model
class Post(models.Model):
title = models.CharField(max_length=500 , verbose_name="عنوان")
slug = models.SlugField(unique=True , verbose_name="آدرس" , allow_unicode=True , db_collation='utf8_persian_ci')
best regards,