好吧,我有使用Django PermissionRequiredMixin這種觀點和IM,當用戶有權限change_item我指定有一切工作正常Django的PermissionRequiredMixin不工作時,用戶沒有所需的權限
from django.contrib.auth.mixins import PermissionRequiredMixin
class MyView(PermissionRequiredMixin,View):
template = 'myapp/item_detail.html'
permission_required = 'myapp.change_item'
def get(self, request, *args, **kwargs):
#Query here
return render(request, self.template)
但是,當用戶沒有它,我得到一個404錯誤頁面說的myapp /登錄這是無效的:
**Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/myapp/login?next=/myapp/item/35/**
The current URL, myapp/login, didn't match any of these.
該登錄它設置LOGIN_URL我們設置與其他一切工作完美......但與此,我也看到它在中間o的登錄字符串f從錯誤的URL ...我錯過了一些關於mixins?,我做錯了什麼?
我添加urls.py:
from django.conf.urls import url
from .views.views_home import HomeView, WelcomeView
from .views.views_authentication import LoginView, LogoutView, ChangePasswordView
urlpatterns = [
url(r'^welcome/$', WelcomeView.as_view(), name="welcome"),
url(r'^home/$', HomeView.as_view(), name="home"),
url(r'^login/$', LoginView.as_view(), name="login"),
url(r'^logout/$', LogoutView, name="logout"),
url(r'^change_password/$', ChangePasswordView.as_view(), name="change_password"),
]
而且堆棧跟蹤:
[03/Oct/2016 17:04:47] "GET /myapp/item/35/ HTTP/1.1" 302 0
Not Found: /myapp/login
[03/Oct/2016 17:04:47] "GET /myapp/login?next=/myapp/item/35/ HTTP/1.1" 404 32312
在此先感謝!
感謝您的回答。正如我之前說的myapp /登錄它是正確的位置,它設置在settings.py中,並完美地與其他重定向一起使用,例如login_required裝飾器...我不知道什麼是錯誤的... – jsanchezs
Sure @ e4c5我剛添加它 – jsanchezs
哦對不起,當然,它也是 – jsanchezs