[英]Couldn't Import GroupRequiredMixin
我想檢查用戶是否在特定的用戶組中。 如果他們在該組中,則可以查看“創建產品”頁面。 在網上看到了該文檔,但目前無法正確使用。
https://django-braces.readthedocs.io/zh-CN/latest/access.html#grouprequiredmixin
我正在嘗試使用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)
我的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"
點凍結:
Django==2.1.5
django-braces==1.13.0
django-polymorphic==2.0.3
pytz==2018.9
謝謝您的寶貴時間。
如果要使用django-braces提供的類,則需要從那里導入它,而不是從未定義它的Django核心導入。 如您要鏈接的文檔所示,您應該from braces.views import GroupRequiredMixin
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.