The login_required decorator¶
<https://docs.djangoproject.com/en/2.0/topics/auth/default/#the-login-required-decorator>
login_required(*redirect_field_name='next'*, *login_url=None*)[source]
<https://docs.djangoproject.com/en/2.0/_modules/django/contrib/auth/decorators/#login_required>
¶
<https://docs.djangoproject.com/en/2.0/topics/auth/default/#django.contrib.auth.decorators.login_required>

As a shortcut, you can use the convenient login_required()
<https://docs.djangoproject.com/en/2.0/topics/auth/default/#django.contrib.auth.decorators.login_required>
decorator:

from django.contrib.auth.decorators import login_required
@login_requireddef my_view(request):
    ...


On Tue, 24 Jul 2018, 01:44 Mostafa Alaa, <[email protected]> wrote:

> the view of  app
>
> from django.shortcuts import render
> from .models import Article
> from django.contrib.auth.decorators import login_required
> # Create your views here.
> def index(request):
>     articles = Article.objects.all()
>     return  render(request,'app/index.html',{'articles':articles})
>
>
>
> def detail(request,slug):
>     articles = Article.objects.get(slug=slug)
>     return render(request, 'app/detail.html', {'articles':articles})
>
>
>
> @login_required
> def create_article(request):
>     return render(request,'app/create.html')
>
>
>
>
>
>
> the settings of login
>
> LOGIN_REDIRECT_URL = '/app/index/'
> LOGIN_URL = '/accounts/login/?next=/'
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/a169e289-8fa7-4bb2-971e-c75b4978474b%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/a169e289-8fa7-4bb2-971e-c75b4978474b%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHV4E-dhSYB8BXF%3Dz8dExMF3SPqt9a4u3sy0j30ai19KQ7Z96Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to