5

I have simple "post" model which represents an entry for my blog:

class Post(models.Model): title = models.CharField('title', max_length=200) slug = models.SlugField('slug', unique_for_date='creation_time') creation_time = models.DateTimeField('creation time', auto_now_add=True) content = models.TextField('content') @permalink def get_absolute_url(self): return ('devblog_post_url', (), { 'year': self.creation_time.year, 'month': self.creation_time.month, 'day': self.creation_time.day, 'slug': self.slug}) 

At the index of my blog, I want to paginate these Posts with this view:

def index_view(request): published_posts = Post.objects.all() paginator = Paginator(published_posts, 10) try: page = int(request.GET.get('page', '1')) except ValueError: page = 1 try: post_list = paginator.page(page) except (EmptyPage, InvalidPage): post_list = paginator.page(paginator.num_pages) return render_to_response('devblog_index.html', {"post_list": post_list}) 

And now here is the problem, I get blank urls once I call the get_absolute_url method for a post with devblog_index.html template:

{% for post in post_list.object_list %} <a href="/{{ post.get_absolute_url }}/">{{ post.title }}</a><br /> {% endfor %} 

EDIT:

Here is my urls.py for my application:

from django.conf.urls.defaults import *

urlpatterns = patterns('', url(r'^$', view='devblog.views.index_view', name='devblog_index' ), url(r'^(?P<year>\d{4})/(?P<month>\w{1,2)/(?P<day>\d{1,2})/(?P<slug>[-\w]+)/$', view='devblog.views.post_view', name='devblog_post_url' ) ) 

at the main urls.py, I simple include it as (r'^blog/', include('devblog.urls'))

Where can be the problem for this blank string url ?

Regards

0

1 Answer 1

5

Change (?P<month>\w{1,2) to (?P<month>\d{1,2}).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.