0

I have the url http://127.0.0.1:8000/shop/جکوزی-آپارتمانی/p/وان-جکوزی-مدل-L188/ in my development project and it's is working fine till i upload it to cpanel which returns Page not found (404)
here is my urls.py:

from django.urls import path , re_path
from . import views as v


urlpatterns = [
    path('', v.index.as_view(), name="ShopView"),
    path('seach/' , v.SearchResultsView.as_view() , name="search_results"),
    re_path(r'c/(?P<categoriese>[-\w]+)/' , v.categoryView , name="ProShopView2"),
    re_path(r'(?P<namecate>[-\w]+)/p/(?P<namepro>[-\w]+)/', v.ProductDetailsView , name="productview"),
    path('products/<str:proname>/comment/' , v.commentView , name="commentviewshop"),

]

first re_path is for category which the url is http://127.0.0.1:8000/shop/c/جکوزی-آپارتمانی/ second re_path is for category and product http://127.0.0.1:8000/shop/جکوزی-آپارتمانی/p/وان-جکوزی-مدل-L188/
here is my category model:

class categories(models.Model):
    name = models.CharField(max_length=50, null=True,blank=True,unique=True)
    url_name = models.SlugField(unique=True , null=True , blank=True,allow_unicode=True)
    image = ResizedImageField(size=[1920,1920], crop=['top', 'left','bottom', 'right'],upload_to = upload_image_path ,   null=True , blank=True)
    def __str__(self):
        return self.name

**here is my productmodel: ** *deleted some of the unnecessary fields.

class productmodel(models.Model):
    Seller = models.ForeignKey(User , on_delete=models.CASCADE , null=True , blank=True) 
    category = models.ForeignKey(categories ,blank=True, null=True, on_delete=models.CASCADE , related_name="categories_main")
    ProductName = models.CharField(max_length=60)
    slug = models.SlugField(unique=True , null=True , blank=True,allow_unicode=True)
    ProductBody = models.TextField(max_length=800)
    image = ResizedImageField(size=[1920,1920], crop=['top', 'left','bottom', 'right'],upload_to = upload_image_path , null=True , blank=True)
    def __str__(self):
        # return f'ProuctName:{self.ProductName} ProductAuthor:{self.author} ProductId:{self.id}'
        return self.ProductName
    def getsnippet(self):
        return self.ProductBody[0:30]

**here is my category views: **

def categoryView(req , categoriese):
    if categories.objects.filter(url_name = categoriese):
        cat = categories.objects.filter(url_name = categoriese)
        for i in cat:
            o = i.id
            pro = productmodel.objects.filter(category = o, deleted=False)
            return render(req , 'shop/shop.html' , {'products':pro} )
    else:
        return redirect("H404")

here is my product views:

def ProductDetailsView(req ,namecate ,namepro):
    cate = categories.objects.get(url_name=namecate)
    if productmodel.objects.get(slug = namepro , category=cate):
        pro = productmodel.objects.get(slug = namepro, category=cate)
        same_pro = productmodel.objects.filter(category=cate)
        commentobject = ModelCommentProduct.objects.filter(accepted = True , post = pro)
        comment_count = commentobject.count()
        context = {'p':pro,'same_pro':same_pro , 'com':commentobject , 'c_count':comment_count}
        return render(req , 'shop/product-details.html' ,context )
    else:
        return redirect("H404")

**I tried re_path which didn't seem to work in cpanel anyway ** my first url parameters were:

path('<str:categoriese>/' , v.categoryView , name="ProShopView2"),
path('products/<str:namecate>/<str:namepro>' , v.ProductDetailsView , name="productview"),

so i changed them to:

re_path(r'c/(?P<categoriese>[-\w]+)/' , v.categoryView , name="ProShopView2"),
re_path(r'(?P<namecate>[-\w]+)/p/(?P<namepro>[-\w]+)/', v.ProductDetailsView , name="productview"),

with allow_unicode=True in models.py i checked persian text in url django but couldn't find my answer

  • What if you try `from urllib.parse import quote, unquote` and use percent-encoded urls e.g. `'http://127.0.0.1:8000/shop' + quote('/جکوزی-آپارتمانی/p/وان-جکوزی-مدل-L188/')`? – JosefZ Jan 04 '23 at 13:20

0 Answers0