My current url pattern is:
url(r'^(?P<category>\w+)/(?P<hash>\w+)/$', article, name='article'),
hash is an alphanumeric string that can be uppercase or lowercase.
example: gqaBittXW9hcyO
What should my url pattern look like to operate for this?
Error:
NoReverseMatch at /news/gqaBittXW9hcyO/
Reverse for 'article' with keyword arguments '{'id': 1, 'category': 'news'}' not found. 1 pattern(s) tried: ['(?P<category>\\w+)/(?P<hash>\\w+)/$']
views
def article(request, category, hash, extra_context=None):
name = resolve(request.path).kwargs['category']
instance = get_object_or_404(Post, hash=hash, entered_category=name)
print('Hash:', instance.hash) #prints correctly (gqaBittXW9hcyO)
context = {
'id': instance.id,
'instance': instance,
}
return render(request, 'article.html', context)