django allauth different layout if not authenticated
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 ?
django django-allauth
add a comment |
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 ?
django django-allauth
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
add a comment |
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 ?
django django-allauth
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 ?
django django-allauth
django django-allauth
asked Nov 13 '18 at 11:26
cwhisperercwhisperer
62811732
62811732
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
add a comment |
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
different layount using same template? or a different template?
– Alex
Nov 13 '18 at 12:37
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
two complete different layouts
– cwhisperer
Nov 13 '18 at 12:47
add a comment |
3 Answers
3
active
oldest
votes
You could use something like that:
{% if user.is_authenticated %}
{% include "subtemplate1.html" %}
{% else %}
{% include "subtemplate2.html" %}
{% endif %}
add a comment |
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',{})
add a comment |
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 templatesaccounts folder I now have a complete login.html page with it's own design and completly separeated from base.html
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
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53280028%2fdjango-allauth-different-layout-if-not-authenticated%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You could use something like that:
{% if user.is_authenticated %}
{% include "subtemplate1.html" %}
{% else %}
{% include "subtemplate2.html" %}
{% endif %}
add a comment |
You could use something like that:
{% if user.is_authenticated %}
{% include "subtemplate1.html" %}
{% else %}
{% include "subtemplate2.html" %}
{% endif %}
add a comment |
You could use something like that:
{% if user.is_authenticated %}
{% include "subtemplate1.html" %}
{% else %}
{% include "subtemplate2.html" %}
{% endif %}
You could use something like that:
{% if user.is_authenticated %}
{% include "subtemplate1.html" %}
{% else %}
{% include "subtemplate2.html" %}
{% endif %}
answered Nov 13 '18 at 14:13
KevinKevin
986
986
add a comment |
add a comment |
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',{})
add a comment |
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',{})
add a comment |
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',{})
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',{})
edited Nov 13 '18 at 16:43
answered Nov 13 '18 at 14:47
AlexAlex
3,5301629
3,5301629
add a comment |
add a comment |
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 templatesaccounts folder I now have a complete login.html page with it's own design and completly separeated from base.html
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
add a comment |
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 templatesaccounts folder I now have a complete login.html page with it's own design and completly separeated from base.html
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
add a comment |
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 templatesaccounts folder I now have a complete login.html page with it's own design and completly separeated from base.html
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 templatesaccounts folder I now have a complete login.html page with it's own design and completly separeated from base.html
answered Nov 14 '18 at 7:18
cwhisperercwhisperer
62811732
62811732
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
add a comment |
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
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
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
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53280028%2fdjango-allauth-different-layout-if-not-authenticated%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
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