URLs for Class Based Views
This is my first try at class based views.
model.py
class Student(models.Model):
emailaddy = models.CharField(max_length=50)
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30)
SIN = models.IntegerField(default=1)
def __str__(self):
return self.last_name
class StudentForm(ModelForm):
class Meta:
model = Student
fields = ['emailaddy', 'first_name', 'last_name', 'SIN']
views.py
class StudentView(CreateView):
form_class = StudentForm
app/urls.py
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^submitted', views.submitted, name='submitted'),
# ex: /app/CES/
url(r'^', views.StudentView, name='CES')
]
This gives me
TypeError at /core/CES.html, __init__() takes 1 positional argument but 2 were given
I read the django docs about class based views and template_names but find it pretty confusing. In their example they have url(r'author/add/$', AuthorCreate.as_view(), name='author-add'), and then it says that CreateView and UpdateView use myapp/author_form.html. I have no idea how that url pattern would find author_form.html.
Changing my url to
url(r'^', StudentView.as_view(), name='CES')
Gives me a different error:
ImproperlyConfigured at /core/CES.html, TemplateResponseMixin requires either a definition of 'template_name' or an implementation of 'get_template_names()
I need a few knowledge gaps filled here, I appreciate any help I can get.
Thanks
Posted Jul 16, 2017, 10:25 PM UTC · edited
06