Search code examples
pythondjangodjango-urlsslug

When to use slug field and query string


I am new in web development in django i don't know when to use slug field and when to use query string parameters in the url.Can anyone suggest me practical differences between them.


Solution

  • Using slugs keep urls simple and clean, thereby easy to remember. Consider the following example:

    example.com/post/hello-world/
    

    v/s

    example.com/?post=hello-world
    

    Obviously, first one is cleaner.

    But query string parameters have their uses too. For example, when you search for an object.

    example.com/search/?q=hello-world
    

    or when you need to pass multiple parameters

    example.com/search/?q=hello+world&lang=en&something=else