I followed a tutorial on django blog creation and I keep getting this error
Reverse for 'article_details_view_url' with arguments '('',)' not found. 1 pattern(s) tried: ['article/(?P<pk>[0-9]+)\\Z']
I have two pages from which I want to link to the blog details page, the home page and index page.
It does link from the home view like so
<a class="links" href="{% url 'article_details_view_url' post.pk %}">{{post.title}}</a>
class HomeView(ListView):
model = Post
template_name = 'home.html'
ordering=['-date_posted']
#ordering=['-id']
def get_context_data(self, *args,**kwargs):
cat_menu = Category.objects.all()
context = super(HomeView, self).get_context_data(*args,**kwargs)
context['cat_menu']=cat_menu
return context
but not from the index view
<a class="links" href="{% url 'article_details_view_url' post.id %}">{{post.title}}</a>
def index(request):
latest_posts = Post.objects.all()
return render(request,'index.html',{
'latest_posts':latest_posts,
})
why is this happening? Can someone direct me to where I need to look to resolve this? Iâm new to this and the documentation is too overwhelming.
NEVERMIND: Got it to work.
I created a for loop on the index page like soâdang it
{% for post in latest_posts %}
<a class="links" href="{% url 'article_details_view_url' post.pk %}">{{post.title}}</a>
<p>{{post.body|slice:100|safe}}</p>
{% endfor %}