[Fixed]-How do I get a url structure that looks like: localhost/science/3, where 'science' is a category and '3' is a story within that category?

1πŸ‘

It sounds like you are after the following

^(?P<cat_name>[\w-]+)/(?P<story_id>\d+)$

which would match up to the view

 def category(request, cat_name, story_id):
       category = Category.objects.get(category_name=cat_name)
       stories = Story.objects.filter(category=category)

Note: you may wish to change what characters are allowed for the category name and this is a pretty wide open regex and may cause you a little trouble with similar urls in the future.

πŸ‘€Sayse

0πŸ‘

You should use:

url(r'^(?P<category_name>\w+)/(?P<story_id>[0-9]+)/$', 'stories.views.comment'),

And in the comment function, define as:

def category(request, category_name, story_id):
πŸ‘€Dric512

Leave a comment