简体   繁体   English

无法导入GroupRequiredMixin

[英]Couldn't Import GroupRequiredMixin

I want to check users if they are in a specific user group. 我想检查用户是否在特定的用户组中。 If they are in that group they can view the "create product" page. 如果他们在该组中,则可以查看“创建产品”页面。 Saw that documentation on web but couldn't use it properly by now. 在网上看到了该文档,但目前无法正确使用。

https://django-braces.readthedocs.io/en/latest/access.html#grouprequiredmixin https://django-braces.readthedocs.io/zh-CN/latest/access.html#grouprequiredmixin

I'm trying to use django-braces > GroupRequiredMixin but when I try to run my server I'm getting that error: 我正在尝试使用django-braces> GroupRequiredMixin,但是当我尝试运行服务器时,却出现了该错误:

File "C:\market\src\products\views.py", line 7, in <module>
    from django.contrib.auth.mixins import GroupRequiredMixin
ImportError: cannot import name 'GroupRequiredMixin' from 'django.contrib.auth.mixins' (C:\market\lib\site-packages\django\contrib\auth\mixins.py)

My views.py looks like this: 我的views.py看起来像这样:

from django.http import Http404
from django.shortcuts import render, get_object_or_404
from django.views.generic import TemplateView
from django.views.generic.edit import CreateView, UpdateView
from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
from django.contrib.auth.mixins import GroupRequiredMixin


from .forms import ProductModelForm, CategoryModelForm
from .models import Product, Category, Stocks


class ProductCreateView(GroupRequiredMixin, SubmitBtnMixin, CreateView):
    model = Product
    template_name = "form.html"
    form_class = ProductModelForm
    submit_btn = "Ürünü Kaydet"
    group_required = u"sellers"

pip freeze: 点冻结:

Django==2.1.5
django-braces==1.13.0
django-polymorphic==2.0.3
pytz==2018.9

Thank you for your time in advance. 谢谢您的宝贵时间。

If you want to use a class provided by django-braces, you need to import it from there, not from core Django which doesn't define it. 如果要使用django-braces提供的类,则需要从那里导入它,而不是从未定义它的Django核心导入。 As the docs you link to show, you should do from braces.views import GroupRequiredMixin . 如您要链接的文档所示,您应该from braces.views import GroupRequiredMixin

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM