I have two major query related to slugurl and pageurl:
What is the exact difference between slugurl
and pageurl
?
Why slugurl
returning None ?
I have two major query related to slugurl and pageurl:
What is the exact difference between slugurl
and pageurl
?
Why slugurl
returning None ?
After debugging the source code found this in side the slugurl simple tag.
@register.simple_tag(takes_context=True)
def slugurl(context, slug):
"""Returns the URL for the page that has the given slug."""
page = Page.objects.filter(slug=slug).first()
if page:
# call pageurl() instead of page.relative_url() here so we get the ``accepts_kwarg`` logic
return pageurl(context, page)
1: What is the exact difference between slugurl
and pageurl
?
Both slugurl
and pageurl
are the tags
slugurl
take slug string as the input where as pageurl
take page object at the input.
NOTE: slugurl
internally call the pageurl
, if the page found with the mention string slug.
2: Why slugurl returning None.?
If you passing any string( let say 'hello') in the slugurl, then the string must be the slug of any Page
page = Page.objects.filter(slug=slug).first()
If the mention string is not assign as the slug of any page, the method will return None
In case you are facing the None issue with slugurl
then follow these two simple steps:
1:Firstly check that any of your page have the mention slug or not.
2:In case of not, please create a page and assign the same slug string in the slug of the newly create page.