Skip to content Skip to sidebar Skip to footer

Django - Have A Class Based View And Crispy Form Parrallell To Each Other On Same Page

Using Django, I am making a site that displays tickets. On the login page, I want it to where there is a preview area of existing tickets to the left of the login form. I am able t

Solution 1:

There are multiple ways to accomplish this. For example, you could create your own login view that 'extends' the one from django.contrib.auth:

from django.contrib.auth.views import login

deflogin_with_preview(request, extra_context=None, *args, **kwargs):
    if extra_context isNone:
        extra_context = {}
    extra_context['object_list'] = Request.objects.all()
    return login(request, authentication_form=LoginForm, extra_context=extra_context, *args, **kwargs)

And then use login_with_preview in your url conf and merge your two templates.

Another possibility is to create a custom template tag. This is especially nice if you want to show this preview list in different places:

@register.inclusion_tag("yourapp/preview_list.html")defticket_preview_list():
    return {'object_list': Request.objects.all()}

preview_list.html should only contain the template code that, right now, is in your preview template block. You need to make sure that template doesn't extend base.html; that would mess things up. The usual template tag setup steps apply.

Solution 2:

You could create one view that renders the login form and the preview data

Post a Comment for "Django - Have A Class Based View And Crispy Form Parrallell To Each Other On Same Page"