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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:45:44+00:00 2026-06-05T19:45:44+00:00

Been stuck on this for ages. Currently learning Django and done some bits on

  • 0

Been stuck on this for ages. Currently learning Django and done some bits on other sites. Starting building my own site and getting stuck with the views / URLS.

I’ve built an app called ‘blog’ where i want to display news posts.

So far I have loaded all the blog items onto a template which is working fine. However when i try and click ‘read more’ the page does not go through to the posts own page. However where it displays the page it’s going to load tells you it’s going to load the correct you URL. So it’s pulling the slug through how I want it but when you click the button it just stays on the same page.

I manage to get it working perfect if i get the blog posts to load on the home page. However I want them to load on /blog/ as obviously I don’t want it to be my homepage.

I’ve read all the documentation and it’s slightly different to the tutorial i’ve been following. Anyhow here is some of my code, really hope someone can help me!

   from django.http import HttpResponse
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext

from blog.models import Blog, NewsPost

def blog_index(request):
    blogs = Blog.objects.filter(active=True)

    return render_to_response('blog/index.html', {
        'blogs':blogs,
    }, context_instance=RequestContext(request))

def blog(request, slug):
    blog = get_object_or_404(Blog, active=True, slug=slug)

    return render_to_response('blog/blog_post.html', {
        'blogs': blogs
    }, context_instance=RequestContext(request))






url(r'blog/', 'blog.views.blog_index', name="blog_index"),
    url(r'blog/(?P<slug>[-\w]+)/$', 'blog.views.blog', name="blog"),

//MODEL

class Blog(TimeStampedActivate):
    title = models.CharField(max_length=255, help_text="Can be anything up to 255 character")
    slug = models.SlugField()
    description = models.TextField(blank=True, help_text="Give a short description of the news post")
    content = models.TextField(blank=True, help_text="This is the main content for the news post")
    user = models.ForeignKey(User, related_name="blog")

    def __unicode__(self):
        return self.title

    @models.permalink
    def get_absolute_url(self):
        return ('blog', (), {
            'slug': self.slug
        })

Thanks,

Josh

  • 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-05T19:45:45+00:00Added an answer on June 5, 2026 at 7:45 pm

    Your url r'blog/' doesn’t have a $ at the end, so I think django will always match this entry rather than the r'blog/(?P<slug>[-\w]+)/$' entry. I’d try reversing the order and see if that helps:

    url(r'blog/(?P<slug>[-\w]+)/$', 'blog.views.blog', name="blog"),
    url(r'blog/', 'blog.views.blog_index', name="blog_index"),
    

    I’ve had that problem before and spent many hours trying to figure it out.

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

Sidebar

Related Questions

I've been stuck at this for quite some time. I've looked at many other
I have been stuck with this problem for quite some time now and i
I've been stuck with this for hours now. I think it's time for some
I've been stuck at this for some time. I SHOULD be really simple. I
I have been stuck on this for some time. Let's say I have a
I've been stuck on this one for some time now and would really appreciate
I have been stuck on this for quite some time. I have searched and
I've been stuck on this for quite a while and would appreciate some help
I've been stuck on this for a while and need some help. I have
I have been stuck on this one for a while, I'm not an expert

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.