5👍
for my case that also worked
{% for section in sections %}
<a href="{% url "base" pk=object.id %}">..</a>
{% endfor %}
where url pattern is
url=[
path('base/<pk>/',base,name='base'),
]
2👍
Each of my models has a list view, a create/update view, and a delete view. These will be used by different functions within the customer’s organisation to maintain the data they are responsible for. Each list view has links to the relevant create, update, and delete views. I wanted to build a page with a list of links to the list view. Here’s how I did it.
I created a function based view in views.py.
def index(request):
app = request.resolver_match.app_name
models = apps.get_app_config(app).get_models()
names = [model._meta.model.__name__ for model in models]
context = {
"names" : names,
}
return render(request, app + '/index.html', context)
I created a template app/templates/app/index.html
{% for name in names %}
<li><a href="{% url request.resolver_match.app_name|add:':'|add:name|lower|add:'-review'%}">{{ name}}</a></li>
{% endfor %}
- Stale content types while syncdb in Django
- Django Python Garbage Collection woes
- Annotate query set with field value
- How do I redirect from a Django DetailView when the specified object doesn't exist?
Source:stackexchange.com