I'm currently developing an application using Django
.
I want to open up camera capture directly when specified as follows in HTML5
tag using Django
.
<input type="file" accept="image/*" capture="camera"/>
In this case, how can I make a field in a model?
Thanks in advance.
Django 3.2.9
CodePudding user response:
Input attributes are set in the widget of the form field, not in the model. In your model you can simply use a FileField.
For example, using a plain form in your forms.py:
class Myform(forms.Form):
myfield=forms.FileField(
widget=forms.FileInput(attrs={'accept': 'image/*', 'capture':'camera'})
)
In case of a model form:
class Myform(forms.ModelForm):
class Meta:
model = YourModel
fields = [myfile]
widgets = {
'myfile': forms.FileInput(attrs={'accept': 'image/*', 'capture':'camera'})
}
CodePudding user response:
You need a FileField type field, your model should have field like this
img = models.FileField(upload_to="/your-local-path")