django 2.13 login_required build-in decorator doesn't work












0














i work on Django 2.1.2 and i wanted decorated my view base on class. I apply login_required decorator in path



path('', login_required(CredentialsList.as_view()), name='credentials-list'),


when i send request to CredentialList it responds normally, it does not redirect me to the login screen. whether I omitted something from the configuration



LOGIN_URL='login/'
LOGIN_REDIRECT_URL = 'list/'









share|improve this question






















  • LOGIN_URL should be an absolute URL, e.g. LOGIN_URL='/login/', or the name of URL patter, e.g. 'login'. LOGIN_REDIRECT_URL is the same.
    – Alasdair
    Nov 20 '18 at 22:43












  • Thank, i notice, i run this project on another enviroment ( another linux ) where everything work fine and i notice that this must be absolute. Thanks Alasdair
    – PiotroSan
    Nov 21 '18 at 8:02
















0














i work on Django 2.1.2 and i wanted decorated my view base on class. I apply login_required decorator in path



path('', login_required(CredentialsList.as_view()), name='credentials-list'),


when i send request to CredentialList it responds normally, it does not redirect me to the login screen. whether I omitted something from the configuration



LOGIN_URL='login/'
LOGIN_REDIRECT_URL = 'list/'









share|improve this question






















  • LOGIN_URL should be an absolute URL, e.g. LOGIN_URL='/login/', or the name of URL patter, e.g. 'login'. LOGIN_REDIRECT_URL is the same.
    – Alasdair
    Nov 20 '18 at 22:43












  • Thank, i notice, i run this project on another enviroment ( another linux ) where everything work fine and i notice that this must be absolute. Thanks Alasdair
    – PiotroSan
    Nov 21 '18 at 8:02














0












0








0







i work on Django 2.1.2 and i wanted decorated my view base on class. I apply login_required decorator in path



path('', login_required(CredentialsList.as_view()), name='credentials-list'),


when i send request to CredentialList it responds normally, it does not redirect me to the login screen. whether I omitted something from the configuration



LOGIN_URL='login/'
LOGIN_REDIRECT_URL = 'list/'









share|improve this question













i work on Django 2.1.2 and i wanted decorated my view base on class. I apply login_required decorator in path



path('', login_required(CredentialsList.as_view()), name='credentials-list'),


when i send request to CredentialList it responds normally, it does not redirect me to the login screen. whether I omitted something from the configuration



LOGIN_URL='login/'
LOGIN_REDIRECT_URL = 'list/'






django login-required






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 '18 at 21:50









PiotroSan

65




65












  • LOGIN_URL should be an absolute URL, e.g. LOGIN_URL='/login/', or the name of URL patter, e.g. 'login'. LOGIN_REDIRECT_URL is the same.
    – Alasdair
    Nov 20 '18 at 22:43












  • Thank, i notice, i run this project on another enviroment ( another linux ) where everything work fine and i notice that this must be absolute. Thanks Alasdair
    – PiotroSan
    Nov 21 '18 at 8:02


















  • LOGIN_URL should be an absolute URL, e.g. LOGIN_URL='/login/', or the name of URL patter, e.g. 'login'. LOGIN_REDIRECT_URL is the same.
    – Alasdair
    Nov 20 '18 at 22:43












  • Thank, i notice, i run this project on another enviroment ( another linux ) where everything work fine and i notice that this must be absolute. Thanks Alasdair
    – PiotroSan
    Nov 21 '18 at 8:02
















LOGIN_URL should be an absolute URL, e.g. LOGIN_URL='/login/', or the name of URL patter, e.g. 'login'. LOGIN_REDIRECT_URL is the same.
– Alasdair
Nov 20 '18 at 22:43






LOGIN_URL should be an absolute URL, e.g. LOGIN_URL='/login/', or the name of URL patter, e.g. 'login'. LOGIN_REDIRECT_URL is the same.
– Alasdair
Nov 20 '18 at 22:43














Thank, i notice, i run this project on another enviroment ( another linux ) where everything work fine and i notice that this must be absolute. Thanks Alasdair
– PiotroSan
Nov 21 '18 at 8:02




Thank, i notice, i run this project on another enviroment ( another linux ) where everything work fine and i notice that this must be absolute. Thanks Alasdair
– PiotroSan
Nov 21 '18 at 8:02












2 Answers
2






active

oldest

votes


















0














Instead you can use the LoginRequiredMixin or the decorator in your view. For example:



# views.py
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.decorators import login_required

# For a class-based view
class CredentialsList(LoginRequiredMixin, TemplateView):

# For a function-based view
@login_required
def credentials_list(request):


and for your url remove the decorator:



path('', CredentialsList.as_view(), name='credentials-list'),





share|improve this answer





















  • You are right, but decorator on class in path is the simplest and faster way, now i think maybe yours is a better way, by the way, i have resolved reason (enviroment) and not resolved problem ( i don't know why enviroment) but I will probably have to create a new environment. Thanks for answer
    – PiotroSan
    Nov 21 '18 at 8:18



















0














I run this project on another linux (ubuntu 16.04), where is another enviroment of course and everything work fine :|. I must check in home what was wrong, maybe must create another virualenv.
Thank you all for your help me!!!






share|improve this answer





















    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%2f53402121%2fdjango-2-13-login-required-build-in-decorator-doesnt-work%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Instead you can use the LoginRequiredMixin or the decorator in your view. For example:



    # views.py
    from django.contrib.auth.mixins import LoginRequiredMixin
    from django.contrib.auth.decorators import login_required

    # For a class-based view
    class CredentialsList(LoginRequiredMixin, TemplateView):

    # For a function-based view
    @login_required
    def credentials_list(request):


    and for your url remove the decorator:



    path('', CredentialsList.as_view(), name='credentials-list'),





    share|improve this answer





















    • You are right, but decorator on class in path is the simplest and faster way, now i think maybe yours is a better way, by the way, i have resolved reason (enviroment) and not resolved problem ( i don't know why enviroment) but I will probably have to create a new environment. Thanks for answer
      – PiotroSan
      Nov 21 '18 at 8:18
















    0














    Instead you can use the LoginRequiredMixin or the decorator in your view. For example:



    # views.py
    from django.contrib.auth.mixins import LoginRequiredMixin
    from django.contrib.auth.decorators import login_required

    # For a class-based view
    class CredentialsList(LoginRequiredMixin, TemplateView):

    # For a function-based view
    @login_required
    def credentials_list(request):


    and for your url remove the decorator:



    path('', CredentialsList.as_view(), name='credentials-list'),





    share|improve this answer





















    • You are right, but decorator on class in path is the simplest and faster way, now i think maybe yours is a better way, by the way, i have resolved reason (enviroment) and not resolved problem ( i don't know why enviroment) but I will probably have to create a new environment. Thanks for answer
      – PiotroSan
      Nov 21 '18 at 8:18














    0












    0








    0






    Instead you can use the LoginRequiredMixin or the decorator in your view. For example:



    # views.py
    from django.contrib.auth.mixins import LoginRequiredMixin
    from django.contrib.auth.decorators import login_required

    # For a class-based view
    class CredentialsList(LoginRequiredMixin, TemplateView):

    # For a function-based view
    @login_required
    def credentials_list(request):


    and for your url remove the decorator:



    path('', CredentialsList.as_view(), name='credentials-list'),





    share|improve this answer












    Instead you can use the LoginRequiredMixin or the decorator in your view. For example:



    # views.py
    from django.contrib.auth.mixins import LoginRequiredMixin
    from django.contrib.auth.decorators import login_required

    # For a class-based view
    class CredentialsList(LoginRequiredMixin, TemplateView):

    # For a function-based view
    @login_required
    def credentials_list(request):


    and for your url remove the decorator:



    path('', CredentialsList.as_view(), name='credentials-list'),






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 20 '18 at 22:08









    Whodini

    50913




    50913












    • You are right, but decorator on class in path is the simplest and faster way, now i think maybe yours is a better way, by the way, i have resolved reason (enviroment) and not resolved problem ( i don't know why enviroment) but I will probably have to create a new environment. Thanks for answer
      – PiotroSan
      Nov 21 '18 at 8:18


















    • You are right, but decorator on class in path is the simplest and faster way, now i think maybe yours is a better way, by the way, i have resolved reason (enviroment) and not resolved problem ( i don't know why enviroment) but I will probably have to create a new environment. Thanks for answer
      – PiotroSan
      Nov 21 '18 at 8:18
















    You are right, but decorator on class in path is the simplest and faster way, now i think maybe yours is a better way, by the way, i have resolved reason (enviroment) and not resolved problem ( i don't know why enviroment) but I will probably have to create a new environment. Thanks for answer
    – PiotroSan
    Nov 21 '18 at 8:18




    You are right, but decorator on class in path is the simplest and faster way, now i think maybe yours is a better way, by the way, i have resolved reason (enviroment) and not resolved problem ( i don't know why enviroment) but I will probably have to create a new environment. Thanks for answer
    – PiotroSan
    Nov 21 '18 at 8:18













    0














    I run this project on another linux (ubuntu 16.04), where is another enviroment of course and everything work fine :|. I must check in home what was wrong, maybe must create another virualenv.
    Thank you all for your help me!!!






    share|improve this answer


























      0














      I run this project on another linux (ubuntu 16.04), where is another enviroment of course and everything work fine :|. I must check in home what was wrong, maybe must create another virualenv.
      Thank you all for your help me!!!






      share|improve this answer
























        0












        0








        0






        I run this project on another linux (ubuntu 16.04), where is another enviroment of course and everything work fine :|. I must check in home what was wrong, maybe must create another virualenv.
        Thank you all for your help me!!!






        share|improve this answer












        I run this project on another linux (ubuntu 16.04), where is another enviroment of course and everything work fine :|. I must check in home what was wrong, maybe must create another virualenv.
        Thank you all for your help me!!!







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 21 '18 at 8:07









        PiotroSan

        65




        65






























            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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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%2f53402121%2fdjango-2-13-login-required-build-in-decorator-doesnt-work%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

            Create new schema in PostgreSQL using DBeaver

            Deepest pit of an array with Javascript: test on Codility

            Costa Masnaga