13👍
✅
as_view
doesn’t take positional arguments, it takes keyword arguments.
EmployeeTemplateView.as_view(emp='employees')
- Django – Check diference between old and new value when overriding save method
- Getting error cannot import name 'six' from 'django.utils' when using Django 3.0.0 latest version
- DRF: Validate nested serializer data when creating, but not when updating
1👍
Since it looks like you are just trying to pass the employees
variable from the view to the template, you can just send it this way:
views.py
from django.views.generic import ListView
from web_app.models import Employee
class EmployeeListView(ListView):
model = Employee
template_name = 'index.html'
context_object_name = 'employees'
urls.py
urlpatterns = [
url(r'^$', EmployeeListView.as_view(), name="employees"),
]
Then you can use the context_object_name
in the template as so:
index.html
<div>{% for employee in employees %} {{ employee }} {% endfor %}</div>
- Django not sending error emails – how can I debug?
- Django: Override Debug=True from manage.py runserver command
- How to mix Django, Uploadify, and S3Boto Storage Backend?
Source:stackexchange.com