Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialManu Febie
3,027 Pointsinclude login form in homeview Django
I want include my login form in my home template, which is a simple Templateview. Below you see the code for login FormView:
"""" from django.contrib.auth.forms import AuthenticationForm
class LoginView(FormView): form_class = AuthenticationForm
template_name = "users/login.html"
def get_form(self, form_class=None):
if form_class is None:
form_class = self.get_form_class()
return form_class(self.request, **self.get_form_kwargs())
def form_valid(self, form):
login(self.request, form.get_user())
return super().form_valid(form)
"""
And this is my homepage view:
""" class Home(TemplateView): template_name = "index.html" """
So basically what I want know is, how can I add the form as context in my home view. Also the Home view and Login view are both in seperate views.py files.