Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 97521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:01:15+00:00 2026-05-11T00:01:15+00:00

When I read Django code I often see in models what is called a

  • 0

When I read Django code I often see in models what is called a "slug". I am not quite sure what this is, but I do know it has something to do with URLs. How and when is this slug-thing supposed to be used?

I have read its definition below in this glossary:

Slug
A short label for something, containing only letters, numbers, underscores or hyphens. They’re generally used in URLs. For example, in a typical blog entry URL:

https://www.djangoproject.com/weblog/2008/apr/12/spring/ the last bit (spring) is the slug.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T00:01:16+00:00Added an answer on May 11, 2026 at 12:01 am

    A ‘slug’ is a way of generating a valid URL, generally using data already obtained. For instance, a slug uses the title of an article to generate a URL. I advise to generate the slug by means of a function, given the title (or another piece of data), rather than setting it manually.

    An example:

    <title> The 46 Year Old Virgin </title> <content> A silly comedy movie </content> <slug> the-46-year-old-virgin </slug> 

    Now let’s pretend that we have a Django model such as:

    class Article(models.Model):     title = models.CharField(max_length=100)     content = models.TextField(max_length=1000)     slug = models.SlugField(max_length=40) 

    How would you reference this object with a URL and with a meaningful name? You could for instance use Article.id so the URL would look like this:

    www.example.com/article/23 

    Or, you might want to reference the title like this:

    www.example.com/article/The 46 Year Old Virgin 

    Since spaces aren’t valid in URLs, they must be replaced by %20, which results in:

    www.example.com/article/The%2046%20Year%20Old%20Virgin 

    Both attempts are not resulting in very meaningful, easy-to-read URL. This is better:

    www.example.com/article/the-46-year-old-virgin 

    In this example, the-46-year-old-virgin is a slug: it is created from the title by down-casing all letters, and replacing spaces by hyphens -.

    Also see the URL of this very web page for another example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 118k
  • Answers 118k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use .AbsoluteUri from a System.Uri (being the Type of Request.RequestUri)… May 11, 2026 at 11:35 pm
  • Editorial Team
    Editorial Team added an answer No, an IEEE 754 double-precision floating point number is always… May 11, 2026 at 11:35 pm
  • Editorial Team
    Editorial Team added an answer No, if you are using a two dimensional array it's… May 11, 2026 at 11:35 pm

Related Questions

I'm somewhat new to Python, Django, and I'd like some advice on how to
I'm a bit stuck with my code: def setVenueImage(img): img = images.Image(img.read()) x, y
I've written an entire app pretty successfully in Django but I have this nagging
I am working on an Orbited -powered website and I'm experiencing some annoying behavior

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.