Answer the question
In order to leave comments, you need to log in
How to pass 2 parameters to urlspatterns?
I have
It sets the template for the main page of the site.
The page has posts (output models) that I would like to connect somehow.
According to the logic (apparently mine), you need to add just one more parameter to the screenshot above.
But, of course, it did not work and knocked out an error.
Please tell me, maybe I should somehow reformulate the function? Tipo so that she receives a model and then displays it in a loop.
Thank you.
Answer the question
In order to leave comments, you need to log in
You need to add data to the context:
from django.views.generic.base import TemplateView
from articles.models import Article
class HomePageView(TemplateView):
template_name = "home.html"
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['latest_articles'] = Article.objects.all()
return context
<h1>Articles</h1>
<ul>
{% for article in latest_articles %}
<li>{{ article.pub_date|date }} - {{ article.headline }}</li>
{% empty %}
<li>No articles yet.</li>
{% endfor %}
</ul>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question