django-views

Django - download file from FileField()

女生的网名这么多〃 提交于 2020-12-06 16:52:25
问题 I'm struggling with the following problem. I have a database model with FileField() . models.py class InputSignal(models.Model): input_file = models.FileField(upload_to='signals/', null=False, ) A view that displays records from this table. It also supports deleting specific rows. views.py def storage_list(request): signals = InputSignal.objects.filter(author=request.user) if request.method == 'DELETE': id = json.loads(request.body)['id'] signal = get_object_or_404(InputSignal, id=id) signal

How do you pass 'exception' argument to 403 view?

心不动则不痛 提交于 2020-12-06 06:54:37
问题 **Edit: Of course, it dawns on me that this doesn't have anything to do with the UserPassesTextMixin, because this error pops up when trying to visit the 403 page directly. Still not sure what to make of it though. I'm attempting to use UserPassesTestMixin to check which model's edit view is being requested and run a test specific to that model to see if the user should have access. Nothing is working yet, I'm just trying to get a feel for how this mixin operates. Upon returning false in the

How do you pass 'exception' argument to 403 view?

偶尔善良 提交于 2020-12-06 06:53:16
问题 **Edit: Of course, it dawns on me that this doesn't have anything to do with the UserPassesTextMixin, because this error pops up when trying to visit the 403 page directly. Still not sure what to make of it though. I'm attempting to use UserPassesTestMixin to check which model's edit view is being requested and run a test specific to that model to see if the user should have access. Nothing is working yet, I'm just trying to get a feel for how this mixin operates. Upon returning false in the

Django UpdateView disable some fields

南笙酒味 提交于 2020-11-27 04:04:38
问题 I have made a class view inheriting UpdateView. I have specified the fields and models from which the forms should be built. Now say if i have a field email, then I want to disable it in the form. I have no clues as to how it can be done. class UserUpdate(UpdateView): model = Users fields = ['email', 'first_name', 'last_name', 'birth_date'] template_name = 'users_update_form.html' success_url = '/index/' 回答1: To hide it: class UserUpdate(UpdateView): model = Users fields = ['first_name',