0

I'm using django with allauth and I need a different layout if the user is not authenticated. In my login.html I cannot use 'extends base.html'. Is this possible without loosing all the features of allauth ?

cwhisperer
  • 1,478
  • 1
  • 32
  • 63

3 Answers3

0

You could use something like that:

{% if user.is_authenticated %}
    {% include "subtemplate1.html" %}
{% else %}
    {% include "subtemplate2.html" %}
{% endif %}
Kevin
  • 143
  • 8
0

Allauth or not, the procedure is the same. In your View you can check if the user is authenticated

def my_view(request):   
  if request.user.is_authenticated: 
      return render(request, 'myapp/index.html' {})
  else: 
      return render(request, 'myapp/logged_in.html',{})

However, it would be better to have different classes :

from django.contrib.auth.decorators import login_required

def my_view(request): 
   if not request.user.is_authenticated: 
       return render(request, 'myapp/index.html' {})
   else: 
       return my_view_auth(request)

@login_required
def my_view_auth(request):
   return render(request, 'myapp/logged_in.html',{})
Alex
  • 5,759
  • 1
  • 32
  • 47
0

Thx for all the answers. I found one solution here which I want to share and have some opinions:

#  urls.py
from django.contrib import admin
from django.urls import path
from django.conf.urls import url, include
from django.views.generic.base import RedirectView
from allauth.account.views import LoginView

class Lvx(LoginView):
    # Login View eXtended
    # beware ordering and collisions on paths
    template_name = "accounts/login.html"

login = Lvx.as_view()

urlpatterns = [
    path('admin/', admin.site.urls),
    url(r'^accounts/login/$', login),
    url(r'^accounts/', include('allauth.urls')),
    url(r'^core/', include('core.urls')),
    url(r'^$', RedirectView.as_view(url='/core'), name='core'),]

In my templates\accounts folder I now have a complete login.html page with it's own design and completly separeated from base.html

cwhisperer
  • 1,478
  • 1
  • 32
  • 63