Django cannot embed a Youtube url in a frame

I am trying to embed a youtube URL into a frame in a Django template. Each time I receive the same message in the console:

Refused to display '' in a frame because it set 'X-Frame-Options' to 'sameorigin'.

I have tried inserting two decorators before the view:


No effect. In a final test I inserted this statement into just to see if it would turn off the xframe check:


The same error appears.

I also tried removing the XFrameOptions middleware, no change.

This is in a local testing environment so I am using the Django web server, my production server (which I have not tried moving this to for obvious reasons) is an Azure instance running NGINX

Are you using an embeddable URL?

It is YouTube that is providing the X-Frame-Options header that the browser is complaining about, which implies you are trying to embed the normal URL to the video.

Back to Top