我想要@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_intent_breh);
if (myBundle != null) {
String name = myBundle.getString("workout");
ShowDetails(name);
}
}
private void ShowAbDetails(String mName) {
if(mName.equals("abs1")){
onBackPressed();
}
}
@Override
public void onBackPressed() {
// your logic here
}
TokenAuthentication
个post
课程。但是对于get
请求,我不想要这个认证类。我怎样才能做到这一点?
class EmailViewSet(viewsets.ModelViewSet):
queryset = Email.objects.all()
authentication_classes = (TokenAuthentication,)
permission_classes = (IsAuthenticated,)
serializer_class = EmailSerializer
def create(self, request, *args, **kwargs):
return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)
这里到底发生的是TokenAuthentication
类适用于所有类型的请求。但我希望此课程仅适用于POST
请求的GET
次请求。
答案 0 :(得分:1)
我认为您可以覆盖get_authenticators
功能:
def get_authenticators(self):
"""
Instantiates and returns the list of authenticators that this view can use.
"""
if self.request.method == "POST":
return [TokenAuthentication()]
return super(EmailViewSet, self).get_authenticators()
然后,从视图中删除authentication_classes
。