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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:05:19+00:00 2026-06-09T10:05:19+00:00

I am currently writing a web-blog, learning django. I need a view to display

  • 0

I am currently writing a web-blog, learning django. I need a view to display a single blog-post and my first try was to create a url for it like the following:

myblog.com/blog/view/1

This uses the blog-id to identify the specified blog-post.

Now if you look at many blogs/website, you see that they use the title of a blog-post in the url, this is because this is more search-engine friendly, so it can be easier found. This might look like this.

myblog.com/blog/view/a-python-backup-script

How do I implement this in django?

Bonus Question:
A lot of sites also include the month and the year of a post. I guess this has also to do with SEO, but how exactly is that useful?

  • 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-09T10:05:20+00:00Added an answer on June 9, 2026 at 10:05 am

    Add a slug field to your Blog model.

    from django.template.defaultfilters import slugify
    
    Class Blog(models.Model):
        title = models.CharField(max_length=40)
        slug = models.SlugField(_('slug'), max_length=60, blank=True)
    
        #Then override models save method:
        def save(self, *args, **kwargs):
            if not self.id:
                #Only set the slug when the object is created.
                self.slug = slugify(self.title) #Or whatever you want the slug to use
            super(Blog, self).save(*args, **kwargs)
    

    In your urls.py

    (r'^blog/view/(?P<slug>[-\w]+)/$', 'app.views.blog_view'),
    

    In views.py

    def blog_view(request, slug):
        blog = Blog.objects.get(slug=slug)
        #Then do whatever you want
    

    EDIT: I added a check in the save method since you want the slug to be created when the object is created. It shouldn’t be saved everytime.

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

Sidebar

Related Questions

I'm learning web-centric programming by writing myself a blog, using PHP with a MySQL
I'm currently writing a web application with django and now put in a button
I am currently writing an web application where you need to log in, using
I'm currently writing a web application. I am using an AjaxFallbackDefaultDataTable to display domain
I'm currently writing a web application that have about 6-12 pages. On each one
I'm currently writing some intranet web application where people could submit to admins requests
I'm currently writing a geographical web application. Obviously it needs access to some geographical
I'm currently writing a JQuery plugin that loads colors from a JSON web service
i'm totally noob to asp.net mvc and currently i'm writing an web app which
I'm writing a web application that connects to a database. I'm currently using a

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.