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

  • Home
  • SEARCH
  • 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 9135753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:51:52+00:00 2026-06-17T08:51:52+00:00

I have some background with python, and I’ve been trying to do a few

  • 0

I have some background with python, and I’ve been trying to do a few Django tutorials, because while I get the general idea, I’m still a beginner so I thought it good practice to just follow along a few examples.

I’m currently working on the “Django by example” tutorial of how to build a simple blog app (here’s a link: http://lightbird.net/dbe/blog.html), and I’ve reached the part where I’m working on the page for each post.

he’s doing a very weird thing there with the redirecting links so I thought it’d be better to do what the Django documentation does with it’s polls app. And here’s the thing – it doesn’t work at all. And not only that, I don’t get an error so I can’t tell what’s wrong, and what really happens makes absolutely zero sense to me.

so this is my urls.py code:

urlpatterns = patterns('',
    url(r'^blog/', 'blog.views.main'),
    url(r'^blog/(?P<post_id>\d+)/$', 'blog.views.post'),
)

this is my views.py code:

def main(request):
    """Main listing."""
    posts = Post.objects.all().order_by("-created")
    paginator = Paginator(posts, 2)

    try: page = int(request.GET.get("page", '1'))
    except ValueError: page = 1

    try:
        posts = paginator.page(page)
    except (InvalidPage, EmptyPage):
        posts = paginator.page(paginator.num_pages)

    return render_to_response("list.html", dict(posts=posts, user=request.user))

def post(request, post_id):
    post = Post.objects.get(pk=post_id)
    d = dict(post=post, user=request.user)
    return render_to_response("post.html", d)

and this is (part of my) html code:

{% for post in posts.object_list %}
    <div class="title">
        <a href="/blog/{{ post.id }}/">{{ post.title }}</a></div>
            <ul>
                <div class="time">{{ post.created }}</div>
                <div class="body">{{ post.body|linebreaks }}</div>
            </ul>
{% endfor %}

so my home page looks fine and its development url is 127.0.0.1:8000/blog
now when I click on a post title (say post number 3) it goes to 127.0.0.1:8000/blog/3, like it should.

But instead of getting the new “post.html” template, it just stays on the damn homepage. trying to change the url and find it directly doesn’t work either.

It’s as if the url patterns looked and found the first option, said “yeah good enough” and didn’t bother to run the others. And the freaky thing is, If I change the post view url in urls.py and get rid of the ‘blog’ part, like this:

url(r'^(?P<post_id>\d+)/$', 'blog.views.post')

it freaking works. but I want to keep the ‘blog’ part in my url, and I don’t get what I’m doing wrong anyway, so even If I’ll just ‘go with whatever’ works i still want to try and understand what’s going on here.

  • 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-17T08:51:53+00:00Added an answer on June 17, 2026 at 8:51 am

    I think you should add a $ to the end of the first url:

    urlpatterns = patterns('',
        url(r'^blog/$', 'blog.views.main'),
        url(r'^blog/(?P<post_id>\d+)/$', 'blog.views.post'),
    )
    

    or you could place the second url before the first url. Django is looking for a match from top to down and will select the first match.

    urlpatterns = patterns('',
        url(r'^blog/(?P<post_id>\d+)/$', 'blog.views.post'),
        url(r'^blog/$', 'blog.views.main'),
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been learning Python by following some pygame tutorials . Therein I found
I have a Django query and some Python code that I'm trying to optimize
I have some code to execute the unix shell command in background in python
I'm coming from a C++ background to python I have been declaring member variables
For some background, I have been programming for many years, but never really touched
I have a python script that runs continuously in background and print some logs
Background: I'm starting off with Django, and have limited experience with Python, so please
I have been trying to get a project of mine to run but I
First some background, I have a python script that will be called periodically by
So for some background: I've been going through learning python the hard way and

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.