Skip to main content

Pretty URLs

A pretty URL is used to transform a default URL with query strings into a more user-friendly and search engine-optimized format, enhancing readability and SEO performance.

Pretty URL Model

ParameterTypeDescription
old_pathstringThe default URL with query strings.
new_pathstringThe search engine-optimized URL.
func_namestringThe view function used to serve the URL (e.g., ProductDetailPageApiView).
func_modulestringThe file name of the func_name.
func_initkwargsJSONThe keyword arguments to get the view.
viewnamestringThe URL name for the old_path (e.g., product).
argslistThe arguments passed to the view function, parsed from the URL.
kwargsJSONAll keyword arguments passed to the view function.
query_paramsJSONThe query parameters of the old_path.
parentPretty URL ModelThe generated pretty URL for default language in multi-language pretty URL objects.
languagestringLanguage used to slugify values of the UrlGeneratorConfig template placeholders to generate new_path.

Whenever an object of the following data models is created, a pretty URL object is automatically generated for default language. If multi-language is enabled a pretty URL is generated for each language, with the one for the default language becoming the parent of the others. Generated pretty URLs are attached to the created object.

Product
CategoryNode
SpecialPage
LandingPage
CategoryNodeLandingPage
Form

When a pretty URL is generated automatically, and a UrlGeneratorConfig object exists, the new_path field is generated using the template and config fields of that object. The values in the template field's placeholders are slugified and then interpolated into the message.

Here is an object of a UrlGeneratorConfig model.

{
"template": "{test}-{test2}",
"config": {
"test": "name",
"test2": "sku"
},
"content_type": {
"pk": 1,
"model": "product"
}
}

The content_type field indicates the model for which the configuration will be used. The keys in the config field are the template placeholders, and the values are the fields of the created object of the models mentioned above.

For example, if a product is created with the following name and SKU:

{
"name": "Kırmızı Erkek Gömlek",
"sku": "5649202702"
}

The new_path field value of the auto-generated pretty URL will be kirmizi-erkek-gomlek-5649202702.

If no UrlGeneratorConfig exists, a default template is used for each data model. The default templates are provided below:

Data modelTemplate
Product{slug}-{color}
CategoryNode{slug}
SpecialPage{url}
LandingPage{url}
CategoryNodeLandingPage{url}
Form{url}

GET List Pretty URLs

This method retrieves a list of pretty URL objects.

Path: https://{storefront_url}/api/v1/pretty_urls/

Header

{
"Authorization": "Token {key}",
"Content-Type": "application/json"
}

Refer to the Login documentation to obtain the authorization key. All endpoints explained on this page require authentication. Make sure to set the header as specified above before sending a request.

Query parameters

ParameterTypeDescription
created_date__gtdateGreater than the created_date field value
created_date__gtedateGreater than or equal to the created_date field value
created_date__ltdateLess than the created_date field value
created_date__ltedateLess than or equal to the created_date field value
modified_date__gtdateGreater than the modified_date field value
modified_date__gtedateGreater than or equal to the modified_date field value
modified_date__ltdateLess than the modified_date field value
modified_date__ltedateLess than or equal to the modified_date field value
languagestringThe language field value
new_pathstringThe new_path field value
new_path__exactstringThe exact value of new_path field, identical to the new_path field above
old_pathstringThe old_path field value
pathstringIt first looks up in new_field. If not found, it will then look up in old_path in the field
parentintThe id value of the parent field
NOTE

If a parameter not listed above is provided, it will return the first page of all objects.

Example Response

{
"count": 1,
"next": null,
"previous": null,
"results": [
{
"pk": 4180,
"new_path": "/testtest/",
"old_path": "/special-page/17/",
"parent": null,
"language": "tr-tr",
"func_module": "omnishop.cms.resources.views",
"func_name": "SpecialPageView",
"func_initkwargs": {},
"args": [],
"kwargs": {
"special_page_id": "17"
},
"query_params": {},
"viewname": "special-page-detail",
"created_date": "2019-11-05T08:18:19.488976Z",
"modified_date": "2019-11-05T08:18:19.489008Z",
"prettyurl_set": []
}
]
}

GET Retrieve Single Pretty URL

This method retrieves a single pretty URL with the given primary key.

Path: https://{storefront_url}/api/v1/pretty_urls/{pk}

Example Response

{
"pk": "<pk>",
"new_path": "<new_path>",
"old_path": "<old_path>",
"parent": null,
"language": "tr-tr",
"func_module": "omnishop.products.resources.views",
"func_name": "ProductDetailPageApiView",
"func_initkwargs": {},
"args": [],
"kwargs": {
"product_id": "1924"
},
"query_params": {},
"viewname": "product",
"created_date": "2017-01-24T10:32:10.487793Z",
"modified_date": "2017-01-30T17:05:10.327456Z",
"prettyurl_set": []
}

POST Create Pretty URL

Path: https://{storefront_url}/api/v1/pretty_urls/

This method is used to create a pretty URL with the following payload.

Request Body

{
"old_path": "<old_path>",
"new_path": "<new_path>"
}

Example Responses

200 OK

{
"pk": 4186,
"new_path": "<new_path>",
"old_path": "<old_path>",
"parent": null,
"language": "tr-tr",
"func_module": "omnishop.products.resources.views",
"func_name": "ProductDetailPageApiView",
"func_initkwargs": {},
"args": [],
"kwargs": {
"extra_query_params": {},
"product_id": "4"
},
"query_params": {},
"viewname": "product",
"created_date": "2023-09-20T13:39:52.562534Z",
"modified_date": "2023-09-20T13:39:52.562610Z",
"prettyurl_set": []
}

406 Not Acceptable

{
"non_field_errors": "Url <old_path> bulunmuyor.",
"error_code": "pretty_url_100_2"
}
{
"non_field_errors": "<new_path> - <language> pretty url mevcut.",
"error_code": "pretty_url_100_1"
}

PATCH Update Pretty URL

This method is used to update the new_path and/or old_path fields.

Path: https://{storefront_url}/api/v1/pretty_urls/{pk}

Request Body

{
"old_path": "<old_path>",
"new_path": "<new_path>",
}

Responses

200 OK

{
"pk": 1432,
"new_path": "<new_path>",
"old_path": "<old_path>",
"parent": null,
"language": "tr-tr",
"func_module": "omnishop.products.resources.views",
"func_name": "ProductDetailPageApiView",
"func_initkwargs": {},
"args": [],
"kwargs": {
"product_id": "1924"
},
"query_params": {},
"viewname": "product",
"created_date": "2017-01-24T10:32:10.487793Z",
"modified_date": "2023-09-20T19:37:52.976216Z",
"prettyurl_set": []
}

406 Not Acceptable

{
"non_field_errors": "Url <old_path> bulunmuyor.",
"error_code": "pretty_url_100_2"
}
{
"non_field_errors": "<new_path> - <language> pretty url mevcut.",
"error_code": "pretty_url_100_2"
}
NOTE

The PUT method works the same as the PATCH method with one exception: both new_path and old_path must be provided.

DELETE Delete Pretty URL

This method is used to delete a pretty URL.

Path: https://{storefront_url}/api/v1/pretty_urls/{pk}

Responses

204 No Content

204 No Content

406 Not Acceptable

{
"non_field_errors": "Cannot delete some instances of model 'PrettyUrl' because they are referenced through a protected foreign key: 'Product.pretty_url': <QuerySet [<Product: [Bad Unicode data]>]>"
}