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 8870267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:40:54+00:00 2026-06-14T17:40:54+00:00

What is @permalink and get_absolute_url in Django? When and why to use it? Please

  • 0

What is @permalink and get_absolute_url in Django? When and why to use it?

Please a very simple example (a real practical example). Thanks

  • 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. Editorial Team
    Editorial Team
    2026-06-14T17:40:55+00:00Added an answer on June 14, 2026 at 5:40 pm

    @permalink is a python decorator, while get_absolute_url is a method on a django model.

    Both are concerned with allowing you to reverse the URL for a particular object and should be used together. They are used anytime you need to provide a link to a particular object or want to display that object’s specific URL (if it has one) to the user

    You could simply write your get_absolute_url method to return a hard coded string, but this wouldn’t adhere to Django’s philosophy of DRY (don’t repeat yourself). Instead, there is the @permalink to make things more flexible.

    If you read the docs on the subject you will see how they relate to each other. the @permalink decorator hooks into django’s URLconf’s backend, allowing you to write much more portable code by using named url patterns. This is preferable to just using get_absolute_url on it’s own: your code becomes much DRYer as you don’t have to specify paths.

    class BlogPost(models.Model):
        name = modelsCharField()
        slug = models.SlugField(...)
    
        @permalink
        def get_absolute_url(self):
            return ("blog-detail", [self.slug,])
    

    and in urls.py

        ...
        url(r'/blog/(?P<slug>[-w]+)/$', blog.views.blog_detail, name="blog-detail")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been following along with the book Practical Django Projects. Very nice book,
I'm currently reading Practical Django Projects and in the Django admin interface there is
hi i am using django app engine patch i have set up a simple
I would like to modify the url to access user profile. OSQA use permalink()
So I want to get the permalink title of a new published post. example
I got a problem on my express server app.get('/callback/:nation/:username/?:permalink', function(req, res) { nationurl =
Can Permalink_fu combine 2 or more model attributes to create a unique permalink? Let's
My permalink structure is set so I have url.com/page I made a basic PHP
This code: $(#permalink a).click(function(id){ var id = this.getAttribute('href'); $(#newPostContent).load(id, function() { $(#removeTrigger).click(function() { $(#removeThis).hideToggle();
I set my wordpress permalink structure to /%postname%/ but now when I go to

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.