[Django]-How to allow only Admin (or some user) to edit the pages in Django?

3👍

views.py

from django.views.generic.edit import UpdateView
from myapp.models import Author

class AuthorUpdate(UpdateView):
    model = Author
    fields = ['name']
    template_name_suffix = '_update_form'

app/author_update_form.html

{% if request.user.is_authenticated and request.user.is_admin %}
<form method="post">{% csrf_token %}
    {{ form.as_p }}
    <input type="submit" value="Update">
</form>
{% else %}
<p>Display data</p>
{% endif %}

Leave a comment