简体   繁体   English

如何包含用户上传的HTML文件-Django

[英]How to include HTML file uploaded by user - Django

I'm including ads in my project's html files i was using GIF files Upload it in the admin and use it like : 我在使用GIF文件的项目的html文件中添加了广告, Upload it in the admin and use it like

{{ ad.image.url }}

but then the client wanted the ad to be HTML file (with js, CSS files) i thought of: 但是后来客户希望广告是HTML文件(带有js,CSS文件),我想到了:

  • Upload a zip file containing all files and extract it to media directory but don't know the best way to achieve this 上载包含所有文件的zip文件,并将其解压缩到媒体目录,但不知道实现此目的的最佳方法
  • upload each file individually and link it to the ad ID but the problem is what if there were directories not just files? 分别上传每个文件并将其链接到广告ID,但问题是如果存在目录而不仅仅是文件呢?

and the main problem is how to inject/include the HTML file content to my HTML page? 主要问题是如何将HTML文件内容注入/包含到我的HTML页面中?

Please share your ideas 请分享您的想法

you can create an upload page for image / css and js files. 您可以为image / css和js文件创建一个上传页面。

and a single html file stored into models or file. 并将单个html文件存储到模型或文件中。

in your view you can load content of html file then pass it to template then render content of passed parameter 在您的视图中,您可以加载html文件的内容,然后将其传递给模板,然后呈现所传递参数的内容

{{ file_content|safe }}

also you can use iframe to show page content 您也可以使用iframe显示页面内容

also to create html file you can use one WYSIWYG 也可以使用一个WYSIWYG创建html文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM