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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:59:03+00:00 2026-05-12T14:59:03+00:00

Just started with Django but hit a bit of a wall – I decided

  • 0

Just started with Django but hit a bit of a wall – I decided to experiment with writing a simple blog engine while referring to the django-basic-apps library.

In blog/urls.py, I have this entry to map to the actual post by date, e.g. blog/2009/aug/01/test-post

urlpatterns = patterns('',
    url(r'^(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{1,2})/(?P<slug>[-\w]+)/$', 'blog.views.post_detail'),
    ...

And the view for rendering the post:

def post_detail(request, slug, year, month, day, **kwargs):
return date_based.object_detail(
    request,
    year = year,
    month = month,
    day = day,
    date_field = 'created_at',
    slug = slug,
    queryset = Content.objects.filter(published=True),
    **kwargs
)

In the model I implemented get_absolute_url so that one the main blog page I could click on a post’s title to view it:

class Content(models.Model):
    ...
@permalink
def get_absolute_url(self):
    return ('blog.views.post_detail', (), {
        'slug': self.slug,
        'year': self.created_at.year,
        'month': self.created_at.strftime('%b').lower(),
        'day': self.created_at.day
    })

Finally, in the main page’s post list, the permalink is supposed to be inserted in the title:

{% for content in object_list %}
<div class="content_list">
<h3 class="content_title"><a href="{{ content.get_absolute_url }}">{{ content.title }}</a></h3>
<p class="content_date">{{ content.published_at|date:"Y F d"}}</p>
<p class="content_body">{{ content.body }}</p>
<p class="content_footer">updated by {{ content.author }} at {{ content.updated_at|timesince }} ago</p>
</div>
{% endfor %}

However the link shows up as empty, and when I try to call content.get_absolute_url() from the django shell the error gets thrown:

NoReverseMatch: Reverse for '<function post_detail at 0xa3d59cc>' with arguments '()' and keyword arguments '{'year': 2009, 'slug': u'another_test', 'day': 15, 'month': 'aug'}' not found.

Edit: Turns out it was a Python namespace problem (see below). But anyway, was my urls.py as shown above incorrect?

  • 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-05-12T14:59:04+00:00Added an answer on May 12, 2026 at 2:59 pm

    Googled around for other newbie Django tutorials and got the idea of putting all the URLs into the parent folder urls.py, and that seemed to solve the problem. 🙂 So in the end, my main urls.py now has:

    from djangoblog.blog import views
    urlpatterns = patterns('',
    
        (r'^blog/(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{1,2})/(?P<slug>[-\w]+)/$',
        views.post_detail),
        (r'^blog/(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{1,2})/$',
        views.post_archive_day),
        ...
    

    Edit: Edit: After 2 days of casual hacking I understand URLconfs + django views a lot better now, fortunately. 🙂 I’ve moved the patterns back into blog/urls.py, got rid of all the custom date-based views and call them from urls.py instead, and properly named patterns for items that need to be @permalinked.

    urls.py with named pattern:

    from blog import views
    ...
    (r'(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{1,2})/(?P<slug>[-\w]+)/$',
        'object_detail', dict(info_dict, slug_field='slug', month_format='%m'),
        'post_detail'),
    ...
    (r'category/(?P<slug>[-\w]+)/$', views.category_detail),
    

    models.py:

    class Post:
        @permalink
        def get_absolute_url(self):
        return ('post_detail', (), {
                      ....
    
    class Category:
        @permalink
    def get_absolute_url(self):
        return ('blog.views.category_detail', (), {'slug': self.slug})
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've just started playing with Django and am loosely following the tutorial with my
I've just started building a prototype application in Django. I started out by working
I just started developing library management system using django. I'm new to Django, so
I've started using django-taggit and it seems to fit the bill. But for me
I want to run a command just before the a django command is started.
Just started ROR Lynda Tutorial, Error while trying to execute the rails server in
Just started getting a bunch of errors on our C# .Net app that seemed
Have just started using Google Chrome , and noticed in parts of our site,
I just started thinking about creating/customizing a web crawler today, and know very little
Have just started using Visual Studio Professional's built-in unit testing features, which as I

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.