我试图只显示一个关闭按钮,如果帖子属于用户,请使用利用刀片authentication,但即时通讯
策略和服务器端运行正常,我可以单击按钮,它将按照我的需要执行,但我只需要看到每个帖子的一个关闭按钮,但是我可能会错误地压缩帖子。
HTML
File "/home/amad/.local/lib/python2.7/site-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/home/amad/.local/lib/python2.7/site-packages/django/core/handlers/base.py", line 249, in _legacy_get_response
response = self._get_response(request)
File "/home/amad/.local/lib/python2.7/site-packages/django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/amad/.local/lib/python2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/amad/.local/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
return view_func(*args, **kwargs)
File "/home/amad/.local/lib/python2.7/site-packages/django/views/generic/base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/rest_framework/views.py", line 483, in dispatch
response = self.handle_exception(exc)
File "/usr/local/lib/python2.7/dist-packages/rest_framework/views.py", line 443, in handle_exception
self.raise_uncaught_exception(exc)
File "/usr/local/lib/python2.7/dist-packages/rest_framework/views.py", line 480, in dispatch
response = handler(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/rest_framework/decorators.py", line 52, in handler
return func(*args, **kwargs)
File "/home/amad/Desktop/djangoshopnroar/userReviews/views.py", line 176, in Calculate_VendorReviewsScore
r = requests.post('http://ns519750.ip-158-69-23.net:8100/func/demo/', data=userdata, headers=headers)
File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 109, in post
return request('post', url, data=data, json=json, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 50, in request
response = session.request(method=method, url=url, **kwargs)
TypeError: request() got an unexpected keyword argument 'category'
PostController.php (帖子页面的视图)
<div class="form-group row">
<div class="col-sm-3 col-sm-offset-1" [ngClass]="{'has-error':!addHotelMappingAmenities.controls['open_time'].valid && (addHotelMappingAmenities.controls['open_time'].dirty || addHotelMappingAmenities.controls['open_time'].touched)}">
<div class="form-material">
<label for="amenity-edit-opens">Opens at</label>
<div id='amenity-edit-opens' class='input-group date'>
<input formControlName="open_time" type='text' class="form-control" id="open_add_amenity" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-time"></span>
</span>
</div>
</div>
<div [ngClass]="{'help-block animated fadeInDown':addHotelMappingAmenities.controls['open_time'].hasError('required') && addHotelMappingAmenities.controls['open_time'].touched}" *ngIf="addHotelMappingAmenities.controls['open_time'].hasError('required') && addHotelMappingAmenities.controls['open_time'].touched">Please select open at.</div>
</div>
<div class="col-sm-3" [ngClass]="{'has-error':!addHotelMappingAmenities.controls['close_time'].valid && (addHotelMappingAmenities.controls['close_time'].dirty || addHotelMappingAmenities.controls['close_time'].touched)}">
<div class="form-material">
<label for="amenity-edit-closes">Closes at</label>
<div id="amenity-edit-closes" class='input-group date'>
<input formControlName="close_time" type='text' class="form-control" id="close_add_amenity" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-time"></span>
</span>
</div>
</div>
<div [ngClass]="{'help-block animated fadeInDown':addHotelMappingAmenities.controls['close_time'].hasError('required') && addHotelMappingAmenities.controls['close_time'].touched}" *ngIf="addHotelMappingAmenities.controls['close_time'].hasError('required') && addHotelMappingAmenities.controls['close_time'].touched">Please select Close at.</div>
</div>
</div>
答案 0 :(得分:1)
我对PHP一无所知,所以我只写简单的文字
因为你在ng-repeat中使用foreach
变化
@foreach($posts as $post)// this is the problem
@if(Auth::user()->can('delete',$post))
<i style="color:red;" class="glyphicon glyphicon-remove" ng-click="deletePost(post)"></i>
@endif
@endforeach
到
@foreach($posts as $post)
@if(Auth::user()->can('delete',$post) && here add some condition like $post.id(php)==post.id(angular))
<i style="color:red;" class="glyphicon glyphicon-remove" ng-click="deletePost(post)"></i>
@endif
@endforeach
或
@if(userIsAuthrise){
<i style="color:red;" class="glyphicon glyphicon-remove" ng-click="deletePost(post)"></i>
}