django allauth different layout if not authenticated












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 ?










share|improve this question























  • 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
















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 ?










share|improve this question























  • 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














0












0








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 ?










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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



















  • 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












3 Answers
3






active

oldest

votes


















0














You could use something like that:



{% if user.is_authenticated %}
{% include "subtemplate1.html" %}
{% else %}
{% include "subtemplate2.html" %}
{% endif %}





share|improve this answer































    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',{})





    share|improve this answer

































      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 templatesaccounts folder I now have a complete login.html page with it's own design and completly separeated from base.html






      share|improve this answer
























      • 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











      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
      });


      }
      });














      draft saved

      draft discarded


















      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









      0














      You could use something like that:



      {% if user.is_authenticated %}
      {% include "subtemplate1.html" %}
      {% else %}
      {% include "subtemplate2.html" %}
      {% endif %}





      share|improve this answer




























        0














        You could use something like that:



        {% if user.is_authenticated %}
        {% include "subtemplate1.html" %}
        {% else %}
        {% include "subtemplate2.html" %}
        {% endif %}





        share|improve this answer


























          0












          0








          0







          You could use something like that:



          {% if user.is_authenticated %}
          {% include "subtemplate1.html" %}
          {% else %}
          {% include "subtemplate2.html" %}
          {% endif %}





          share|improve this answer













          You could use something like that:



          {% if user.is_authenticated %}
          {% include "subtemplate1.html" %}
          {% else %}
          {% include "subtemplate2.html" %}
          {% endif %}






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 13 '18 at 14:13









          KevinKevin

          986




          986

























              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',{})





              share|improve this answer






























                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',{})





                share|improve this answer




























                  0












                  0








                  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',{})





                  share|improve this answer















                  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',{})






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 13 '18 at 16:43

























                  answered Nov 13 '18 at 14:47









                  AlexAlex

                  3,5301629




                  3,5301629























                      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 templatesaccounts folder I now have a complete login.html page with it's own design and completly separeated from base.html






                      share|improve this answer
























                      • 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
















                      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 templatesaccounts folder I now have a complete login.html page with it's own design and completly separeated from base.html






                      share|improve this answer
























                      • 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














                      0












                      0








                      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 templatesaccounts folder I now have a complete login.html page with it's own design and completly separeated from base.html






                      share|improve this answer













                      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







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      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



















                      • 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


















                      draft saved

                      draft discarded




















































                      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.




                      draft saved


                      draft discarded














                      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





















































                      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







                      Popular posts from this blog

                      Bressuire

                      Vorschmack

                      Quarantine