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 ?
Asked
Active
Viewed 203 times
0
-
different layount using same template? or a different template? – Alex Nov 13 '18 at 12:37
-
two complete different layouts – cwhisperer Nov 13 '18 at 12:47
3 Answers
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
-
it is not clear what you try to do or why you make it more complicated then it is. – Alex Nov 15 '18 at 14:02