You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Following your comment, I tested v0.6.0.
Unfortunately, {{ form.media }} is rendered as None
Maybe I have missed something in the instructions ?
See below my forms.py, widgets.py and the HTML template
Forms.py
class NoteForm(CSPFormMixin, ModelForm):
class Meta:
model = Note
fields = ('datetime', 'text', 'image')
field_classes = {
'datetime': SplitDateTimeField # Use a SplitDateTimeField
}
widgets = {
'text': Textarea(attrs={'rows': 4}),
'datetime': SplitDateTimePickerWidget,
'image': ImageWidget(attrs={'accept': 'image/*'})
}
labels = {
'image': _('Photos')
}
Heya! You need to use both CSPViewMixin and CSPFormMixin - the mixin on the view passes the nonce to the form. Django forms have no access to the request, so they can't get it on their own.
If you're not using FormView, and can't use the view mixin, you just need to call your form with csp_nonce as an argument (something like this code below).
MyForm(csp_nonce=request.csp_nonce)
If that isn't your problem, let me know and I can investigate further.
Many thanks for django-csp-helpers :-)
Following your comment, I tested v0.6.0.
Unfortunately, {{ form.media }} is rendered as None
Maybe I have missed something in the instructions ?
See below my forms.py, widgets.py and the HTML template
Forms.py
widgets.py
HTML template
The text was updated successfully, but these errors were encountered: